Redirect if not signed in with withPageAuthRequired()

Please include the following information in your post:

  • Which SDK this is regarding: @auth0/nextjs-auth0
  • SDK Version: ^1.7.0
  • Platform Version: v16.13.2

I’m just trying out auth0 and nextjs, so apologies if this is a silly question, but what I’d like to do is if a user is not signed in when trying to access certain pages, I’d like them to be redirected to the index page.

The default behavior is to redirect users to the sign in page on auth0.

import React from 'react';
import { withPageAuthRequired } from '@auth0/nextjs-auth0';

export default function Profile({ user }) {
  return (
    user && (
      <div>
        <img src={user.picture} alt={user.name} />
        <h2>{user.name}</h2>
        <p>{user.email}</p>
        <a href="/api/auth/logout">Logout</a>
      </div>
    )
  );
}

export const getServerSideProps = withPageAuthRequired();

Is there a way to configure this behavior or is it only possible in client side rendering?