Configuring nextjs-auth0 withPageAuthRequired with multi-tenant app

  • Which SDK this is regarding: nextjs-auth0
  • SDK Version: 1.9.1

Hey there! Working on converting our SPA to a MPA with NextJS. We have a single app that allows multiple tenants to connect to it. My custom initAuth0 function queries for the tenant information from our database to populate the required parameters.

export default async (req: NextApiRequest) => {
  try {
    const auth0Config = await appSyncClient.query<any>({
      query: GET_AUTH0_CONFIG_QUERY,
    });

    return initAuth0({
      ...auth0Config 
    });
  } catch (e) {
    console.log('Error initilizing Auth0 client');
  }
};

This works fine so far, but I need to send a request with every version of the instance (I think?) in order to grab the configuration. This all works fine except I’m having a hard time with withPageAuthRequired.

withPageAuthRequired(DashboardPage)

doesnt work because I need to send the req to the initAuth0 instance. I tried

export const getServerSideProps = async req => {
  const auth = await auth0(req);
  return auth?.withPageAuthRequired();
};

as well but getServerSideProps expects and object to be returned. Any hints here?

Turns out you can just use the SDK’s version, as initAuth0 is only for server side methods according to this issue:

So, closing

1 Like