How persist the user session?

Hi, I have a question how to persist the session of a user. I mean what I want is when the user uses the app the access token increase it life time. I know about the refresh token, I have enabled it but it does not work, is some other config necessary or what? Please help and if someone have a respoitory with an example, I will be thankful.

Hey there @lagui2003 !

It really depends on your particular use case, but in general refresh tokens are the way to go.
When you say that it does not work, are you able to be a bit more specific?

Alternatively, in some cases silent authentication can have the same effect.

Thank you for your reply. What I mean is for example, if I have an access token that lasts 1 week, if I enter the application one day before the token expires, with the refresh token I can extend the duration of the session. Is this possible and if so, is it automatic or do I have to make an additional configuration?

1 Like

No problem, happy to help where I can!

If you have an application properly configured to use refresh tokens/refresh token rotation (SPA for example) then whichever SDK you are using should handle this automatically for you. In auth0-react for example, you will need to be sure and set useRefreshTokens to true in your Auth0Provider:

In my case I am using the Nextjs SDK. How do I know if I have everything configured correctly with the refresh token, do you have any resources that can guide me .

This is the code in the middleware I am using. https://github.com/Laguilavo10/Cost-Manager/blob/main/src/middleware.ts

Hey @lagui2003 sorry for the delayed response!

It should be fairly straightforward and is outline in the SDK docs here:

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