Skip to content

Instantly share code, notes, and snippets.

@itwasmattgregg
Created October 22, 2022 21:26
Show Gist options
  • Save itwasmattgregg/aad358ec48b29bac9e3e46890943e8bb to your computer and use it in GitHub Desktop.
Save itwasmattgregg/aad358ec48b29bac9e3e46890943e8bb to your computer and use it in GitHub Desktop.
import { withIronSessionApiRoute, withIronSessionSsr } from 'iron-session/next';
const sessionOptions = {
password: process.env.SECRET_COOKIE_PASSWORD,
cookieName: 'next-iron-session/examples/next.js',
// secure: true should be used in production (HTTPS) but can't be used in development (HTTP)
cookieOptions: {
secure: process.env.NODE_ENV === 'production',
},
};
export function withSessionRoute(handler) {
return withIronSessionApiRoute(handler, sessionOptions);
}
export function withSessionSsr(handler) {
return withIronSessionSsr(handler, sessionOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment