# How do I manage the user's authentication state when creating users? nextjs-auth0 has limited capability

**URL:** <https://community.auth0.com/t/how-do-i-manage-the-users-authentication-state-when-creating-users-nextjs-auth0-has-limited-capability/119463>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [October 26, 2023, 2:42pm UTC](https://community.auth0.com/t/how-do-i-manage-the-users-authentication-state-when-creating-users-nextjs-auth0-has-limited-capability/119463 "2023-10-26T14:42:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajtoo](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@ajtoo](https://community.auth0.com/u/ajtoo)\
**Post date:** [October 26, 2023, 2:42pm UTC](https://community.auth0.com/t/how-do-i-manage-the-users-authentication-state-when-creating-users-nextjs-auth0-has-limited-capability/119463/1 "2023-10-26T14:42:16Z")

</div>

Overall, the problem boils down to “how do I update the login state on the client side in nextjs-auth0 with valid credentials/information?”. Below is the more detailed description.

I successfully set up the login flow and protected some pages using withPageAuthRequired. I am using Nextjs 13 and Apollo Client in conjunction with Auth0. However, I’m looking to add support for a few things:

1. **custom user creation** I need to sign the user on after they go through a custom user creation process. How would i get back a token then update the state in nextjs-auth0? It’s very unclear to me

2. **token refresh cycle** I would like to continue refreshing my users’ tokens while they are actively using the site. How would I update the state in nextjs-auth0/consume a refresh token to keep my user logged in?

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [October 31, 2023, 7:45pm UTC](https://community.auth0.com/t/how-do-i-manage-the-users-authentication-state-when-creating-users-nextjs-auth0-has-limited-capability/119463/3 "2023-10-31T19:45:23Z")

</div>

Hi @ajtoo

Welcome to the Auth0 Community!

1. **Custom User creation and token fetching** :  
For the given example I would suggest checking out [Authorization Code Flow with Proof Key for Code Exchange (PKCE)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-proof-key-for-code-exchange-pkce), which is done behind the curtains if you use [auth0-spa-js]([https://What](https://What) exactly happens behind the curtains here?)

 ![](https://global.discourse-cdn.com/auth0/original/3X/a/6/a648f2ccf1651bd909e1b299e687147751b1f714.png)

1. **Silent Auth** :  
From what I’ve checked there’s no plug-in function that will do silent auth in the next-js=auth0 (according to our GitHub repository), but I found a discussion on how to implement this. feature [What is the best way to do silent authentication in V2? · Issue #1207 · auth0/nextjs-auth0 · GitHub](https://github.com/auth0/nextjs-auth0/issues/1207#issuecomment-1776103125)

I would also recommend checking out our latest guide about Next.js Authentication

> **[Next.js Authentication By Example: Using App Router](https://developer.auth0.com/resources/guides/web-app/nextjs/basic-authentication?_gl=1*b6znpl*_gcl_au*MjExNDU0MDU4OS4xNjk0NTI4MzQ1#add-user-login-to-next-js)**
>
> Learn how to add authentication features to Next.js apps: add login, logout, and sign-up. Learn how to integrate Auth0 with the Next.js App Router to protect Next.js pages and how to call protected APIs.

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![ajtoo](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@ajtoo](https://community.auth0.com/u/ajtoo)\
**Post date:** [October 31, 2023, 9:39pm UTC](https://community.auth0.com/t/how-do-i-manage-the-users-authentication-state-when-creating-users-nextjs-auth0-has-limited-capability/119463/4 "2023-10-31T21:39:13Z")

</div>

Hi Dawid,

I actually had a look through these options. I think the problem here is that I need to support a custom sign up via a Rails API that also populates data on that API side. I’ve been trying to consume Auth0 more as an API while waiting for the reply. I think the big kicker overall is the App Router making it difficult to handle the credentials.

In any scenario, I need to be able to pass the credentials along with my GraphQL request and it seems to be a bit of a struggle depending on where I am in the render cycle. In the RSC render, it seems like we’re cut off from anywhere that we could retrieve a token from to make a request. On SSR, it seems like it depends on the scenario. (Client side is obviously simple and straightforward).

Auth0 describes that we should store the token in memory and not on, say, localSession. Where exactly would this be?

---

<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 14, 2023, 9:40pm UTC](https://community.auth0.com/t/how-do-i-manage-the-users-authentication-state-when-creating-users-nextjs-auth0-has-limited-capability/119463/5 "2023-11-14T21:40:10Z")

</div>

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