Last active
May 20, 2023 13:45
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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