Nextjs-auth0: protect all pages

  • Which SDK this is regarding: nextjs-auth0
  • SDK Version: 1.6.1
  • Platform Version: NextJS 12.0.7

Hi,

Following Auth0 SDK docs we can protect each NextJS page by wrapping them with the withPageAuthRequired, like this:

// pages/profile.js
import { withPageAuthRequired } from '@auth0/nextjs-auth0';

export default withPageAuthRequired(function Profile({ user }) {
  return <div>Hello {user.name}</div>;
});

Is there a way to protect all the pages at once instead of using the withPageAuthRequired on each page?

Hi @chenriques,

Welcome to the Auth0 Community!

Unfortunately, it’s not possible. After checking the Auth0 Next.js SDK, I found that there isn’t an alternative way to wrap authentication to all your pages.

Given that, you’ll need to continue using the withPageAuthRequired to protect the pages you need with authentication.

I hope this helps!

Please let me know if you have any further questions.

Thank you.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.