Wrap your getServerSideProps with this method to make sure the user is authenticated before visiting the page.
getServerSideProps
// pages/protected-page.jsimport { withPageAuthRequired } from '@auth0/nextjs-auth0';export default function ProtectedPage() { return <div>Protected content</div>;}export const getServerSideProps = withPageAuthRequired(); Copy
// pages/protected-page.jsimport { withPageAuthRequired } from '@auth0/nextjs-auth0';export default function ProtectedPage() { return <div>Protected content</div>;}export const getServerSideProps = withPageAuthRequired();
If the user visits /protected-page without a valid session, it will redirect the user to the login page. Then they will be returned to /protected-page after login.
/protected-page
Optional
Wrap your
getServerSideProps
with this method to make sure the user is authenticated before visiting the page.If the user visits
/protected-page
without a valid session, it will redirect the user to the login page. Then they will be returned to/protected-page
after login.