Skip to content

Instantly share code, notes, and snippets.

@srph
Created November 12, 2022 04:46
Show Gist options
  • Save srph/29bea326b3ac358de332f0eb416bec83 to your computer and use it in GitHub Desktop.
Save srph/29bea326b3ac358de332f0eb416bec83 to your computer and use it in GitHub Desktop.
auth0-nextjs: Authorize by role
export const getServerSideProps = withPageAuthRequired({
async getServerSideProps(ctx) {
const whitelisted = ['[email protected]']
const session = getSession(ctx.req, ctx.res)
if (!whitelisted.includes(session.user.email)) {
return {
redirect: {
destination: '/logout',
permanent: false,
},
props: {},
}
}
return { props: {} }
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment