diff options
author | 2021-08-09 21:36:03 +0200 | |
---|---|---|
committer | 2021-08-09 21:37:03 +0200 | |
commit | 464e470441287572cfda8d95484f781236b9db35 (patch) | |
tree | 87177837cb6ee6ee000f0d39fa5ba7ee6bb2943e /lib/withSession.js | |
download | my_apps-464e470441287572cfda8d95484f781236b9db35.tar.gz my_apps-464e470441287572cfda8d95484f781236b9db35.tar.bz2 my_apps-464e470441287572cfda8d95484f781236b9db35.zip |
init commit
Diffstat (limited to 'lib/withSession.js')
-rw-r--r-- | lib/withSession.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/withSession.js b/lib/withSession.js new file mode 100644 index 0000000..0361db3 --- /dev/null +++ b/lib/withSession.js @@ -0,0 +1,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, + }, + }) +} |