# Configuring nextjs-auth0 withPageAuthRequired with multi-tenant app

**URL:** <https://community.auth0.com/t/configuring-nextjs-auth0-withpageauthrequired-with-multi-tenant-app/87060>\
**Category:** Get Help\
**Created:** [July 15, 2022, 6:12pm UTC](https://community.auth0.com/t/configuring-nextjs-auth0-withpageauthrequired-with-multi-tenant-app/87060 "2022-07-15T18:12:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob.granberry](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jacob.granberry/32/35615_2.png) [@jacob.granberry](https://community.auth0.com/u/jacob.granberry)\
**Post date:** [July 15, 2022, 6:12pm UTC](https://community.auth0.com/t/configuring-nextjs-auth0-withpageauthrequired-with-multi-tenant-app/87060/1 "2022-07-15T18:12:51Z")

</div>

- 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.

```auto
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`.

```auto
withPageAuthRequired(DashboardPage)

```

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![jacob.granberry](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jacob.granberry/32/35615_2.png) [@jacob.granberry](https://community.auth0.com/u/jacob.granberry)\
**Post date:** [July 18, 2022, 2:00pm UTC](https://community.auth0.com/t/configuring-nextjs-auth0-withpageauthrequired-with-multi-tenant-app/87060/2 "2022-07-18T14:00:54Z")

</div>

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

> <https://github.com/auth0/nextjs-auth0/issues/536#issuecomment-967229110>
>
> \### Description
> 
> Could you provide a solution for that scenario when we want t…o use the \`withPageAuthRequired()\` on CSR, but with an own instance? We use AWS secret manager to get the secrets for Auth0. 
> 
> Following \[your guidance\](https://github.com/auth0/nextjs-auth0/issues/376#issuecomment-833488401) and the official Auth0 example from \[here\](https://github.com/auth0/nextjs-auth0/blob/v1.6.1/EXAMPLES.md#protecting-a-client-side-rendered-csr-page), we try to get this working with a code like this:
> 
> \`\`\`
> import {auth0} from '../../../utils/auth0';
> 
> const AuthRequiredCSRExample = props =\> {
> // stuff...
> 
> return (
> \<\>
> \<p\>more stuff...\</p\>
> \</\>
> );
> };
> 
> const instance = await auth0();
> 
> export default instance.withPageAuthRequired(AuthRequiredCSRExample);
> 
> \`\`\`
> 
> In the \`next.config.js\` I had to enable the top-level-await feature:
> 
> \`\`\`
> config.experiments = {
> ...config.experiments,
> topLevelAwait: true
> };
> \`\`\`
> 
> But now I got an error message on the page which says:
> !\[image\](https://user-images.githubusercontent.com/1906302/140893645-23c6dbb1-a584-41b7-b461-b0402b44452f.png)
> 
> It looks like if we have to get the secrets from somewhere (e.g. AWS secret manager), we lose the ability to use this CSR \`withPageAuthRequired()\` feature. But correct me, please if I'm wrong!
> 
> Any help would be appreciated!
> 
> \### Environment
> \- Version of this library used: 1.6.1
> \- Version of the platform or framework used, if applicable: Next.js 12.0.2

So, closing

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 28, 2022, 1:12pm UTC](https://community.auth0.com/t/configuring-nextjs-auth0-withpageauthrequired-with-multi-tenant-app/87060/3 "2022-07-28T13:12:41Z")

</div>


