WithPageAuthRequiredPageRouterOptions<P, Q>: {
    getServerSideProps?: GetServerSideProps<P, Q>;
    returnTo?: string;
}

If you have a custom returnTo url you should specify it in returnTo.

You can pass in your own getServerSideProps method, the props returned from this will be merged with the user props. You can also access the user session data by calling getSession inside of this method. For example:

// pages/protected-page.js
import { getSession, withPageAuthRequired } from '@auth0/nextjs-auth0';

export default function ProtectedPage({ user, customProp }) {
return <div>Protected content</div>;
}

export const getServerSideProps = withPageAuthRequired({
// returnTo: '/unauthorized',
async getServerSideProps(ctx) {
// access the user session if needed
// const session = await getSession(ctx.req, ctx.res);
return {
props: {
// customProp: 'bar',
}
};
}
});

Type Parameters

  • P extends {
        [key: string]: any;
    } = {
        [key: string]: any;
    }

  • Q extends ParsedUrlQuery = ParsedUrlQuery

Type declaration

  • Optional getServerSideProps?: GetServerSideProps<P, Q>
  • Optional returnTo?: string