# "nextjs" Auth0 page protection and secure API call

**URL:** <https://community.auth0.com/t/nextjs-auth0-page-protection-and-secure-api-call/111887>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [July 23, 2023, 9:14am UTC](https://community.auth0.com/t/nextjs-auth0-page-protection-and-secure-api-call/111887 "2023-07-23T09:14:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haitham](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@haitham](https://community.auth0.com/u/haitham)\
**Post date:** [July 23, 2023, 9:14am UTC](https://community.auth0.com/t/nextjs-auth0-page-protection-and-secure-api-call/111887/1 "2023-07-23T09:14:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![its](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@its](https://community.auth0.com/u/its)\
**Post date:** [July 23, 2023, 4:21pm UTC](https://community.auth0.com/t/nextjs-auth0-page-protection-and-secure-api-call/111887/2 "2023-07-23T16:21:50Z")

</div>

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:

> <https://github.com/auth0/nextjs-auth0/issues/1235>
>
> v3 of this SDK is now available on Beta.
> 
> The main update is support for Next.…js 13.4's \[App Router\](https://nextjs.org/docs/app)
> 
> \> \*\*Edit:\*\* https://github.com/auth0/nextjs-auth0/releases/tag/v3.0.0-beta.3 adds full support for the Edge runtime
> 
> To install:
> 
> \`\`\`bash
> $ npm i @auth0/nextjs-auth0@beta
> \`\`\`
> 
> For more information about how to use the SDK in the app directory, see these resources:
> 
> \- Basic setup: https://github.com/auth0/nextjs-auth0/tree/beta#app-router (note the section on \[App Router limitations\](https://github.com/auth0/nextjs-auth0/tree/beta#important-limitations-of-the-app-directory))
> \- Example app:
> - \[The auth handlers route\](https://github.com/auth0/nextjs-auth0/blob/beta/example-app/app/api/auth/%5Bauth0%5D/route.ts)
> - \[Protecting a page\](https://github.com/auth0/nextjs-auth0/blob/beta/example-app/app/profile/page.tsx) (note \[returnTo limitations\](https://github.com/auth0/nextjs-auth0/blob/beta/src/helpers/with-page-auth-required.ts#L145))
> - \[Protecting an API\](https://github.com/auth0/nextjs-auth0/blob/beta/example-app/app/api/profile/route.ts)
> - \[Usage in a server component\](https://github.com/auth0/nextjs-auth0/blob/beta/example-app/app/server-component.tsx)
> - \[Usage in a client component\](https://github.com/auth0/nextjs-auth0/blob/beta/example-app/app/client-component.tsx)
> 
> If you notice any problems, please raise a new issue with the \`beta\` label

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

> <https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#access-an-external-api-from-an-api-route>

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 26, 2024, 11:45pm UTC](https://community.auth0.com/t/nextjs-auth0-page-protection-and-secure-api-call/111887/3 "2024-11-26T23:45:40Z")

</div>

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