Wrap your getServerSideProps with this method to make sure the user is authenticated before visiting the page.
getServerSideProps
// pages/protected-page.jsimport { auth0 } from "@/lib/auth0";export default function ProtectedPage() { return <div>Protected content</div>;}export const getServerSideProps = auth0.withPageAuthRequired(); Copy
// pages/protected-page.jsimport { auth0 } from "@/lib/auth0";export default function ProtectedPage() { return <div>Protected content</div>;}export const getServerSideProps = auth0.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.