aboutsummaryrefslogtreecommitdiffstats
path: root/lib/withSession.js
blob: 0361db3e6c64366bf85332676f44b25ec0547ea9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// this file is a wrapper with defaults to be used in both API routes and `getServerSideProps` functions
import {withIronSession} from 'next-iron-session'

export default function withSession(handler) {
  return withIronSession(handler, {
    password: process.env.MYAPPS_SECRET_COOKIE_PASSWORD,
    cookieName: 'myapps_session',
    cookieOptions: {
      // the next line allows to use the session in non-https environments like
      // Next.js dev mode (http://localhost:3000)
      secure: process.env.NODE_ENV === 'production' ? true : false,
    },
  })
}