"nextjs" Auth0 page protection and secure API call

Hello All,

I am attempting to implement Auth0 for our application, which utilizes Next.js for the frontend and Spring Boot for the backend. I’ve successfully implemented Auth0 login in Next.js using the App route structure, which required me to create a new folder named “pages” to comply with the instructions provided by Auth0. Although I am not entirely confident about this process, I managed to get it working.

However, I still need to address the following tasks:

  1. Secure Next.js pages (only authenticated users should be able to access these, others should be redirected to the login page).
  2. Secure endpoints in Java (Spring Boot).
  3. Send secure calls from Next.js to the backend APIs.

I’m a little lost on how to protect pages in Next.js. I understand that I need to use “withPageAuthRequired”, but it appears to work only with Page router, not the App router.

Furthermore, I am encountering numerous deprecated functions and issues related to using the App router in Next.js and ‘org.springframework.boot’ version ‘3.0.6’ in the backend.

I’m not a regular on this forum but just happened to see your post.

The app directory is sort of new. next auth0 isn’t caught up to it yet. There is a beta though. You can read about it’s status here:

For 3rd party API calls you need to grab the access token.

1 Like