weddingsite/lib/session.js

16 lines
603 B
JavaScript
Raw Permalink Normal View History

2021-06-04 00:58:40 +00:00
// this file is a wrapper with defaults to be used in both API routes and `getServerSideProps` functions
import { withIronSessionApiRoute } from 'iron-session/next';
2021-06-04 00:58:40 +00:00
export default function withSession(handler) {
return withIronSessionApiRoute(handler, {
2021-06-04 00:58:40 +00:00
password: process.env.SECRET_COOKIE_PASSWORD,
cookieName: 'weddingwebsitesession',
cookieOptions: {
// the next line allows to use the session in non-https environments like
// Next.js dev mode (http://localhost:3000)
// maxAge default is 14 days
2021-06-04 00:58:40 +00:00
secure: process.env.NODE_ENV === 'production',
},
});
}