Skip to content

Instantly share code, notes, and snippets.

@akellbl4
Last active May 20, 2023 13:45
Show Gist options
  • Save akellbl4/8e7c22092d9c4123a847fbeb05c03798 to your computer and use it in GitHub Desktop.
Save akellbl4/8e7c22092d9c4123a847fbeb05c03798 to your computer and use it in GitHub Desktop.
Code example for the article: "Why I got rid of getInitialProps on my work Next.js project"
export function authWrapper(next) {
return async function auth(ctx) {
const user = await session.getUser();
if (!user) {
return {
redirect: {
destination: '/sign-in',
permanent: false,
},
};
}
const props = { user };
return typeof next === 'function' ? next(ctx, props) : { props };
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment