# Nextjs rolling session

**URL:** <https://community.auth0.com/t/nextjs-rolling-session/74163>\
**Category:** Get Help\
**Created:** [December 2, 2021, 10:50pm UTC](https://community.auth0.com/t/nextjs-rolling-session/74163 "2021-12-02T22:50:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![francesco.venica](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/francesco.venica/32/13023_2.png) [@francesco.venica](https://community.auth0.com/u/francesco.venica)\
**Post date:** [December 2, 2021, 10:50pm UTC](https://community.auth0.com/t/nextjs-rolling-session/74163/1 "2021-12-02T22:50:38Z")

</div>

Hello,

I have an app in nextjs, I’m using the official auth0 sdk, I would like to keep id\_token and access token short live (~30sec), the cookie in the app should update itself in order to expire always after 15min, if the user doesn’t interact with the app after 15min I should be logged out…if the cooke expire without an interaction I should be force to re-login and all the token must be useless…I’m a bit confused on how I should achieve this, my idea is to set:

- tenant: Inactivity timeout = 15min
- api: Token Expiration For Browser Flows / Token Expiration to 30 sec
- app: id token in the app 30 sec
- app: Refresh Token Rotation 120 sec (but it should be \>30sec if I’m not wrong)
- app: Refresh Token Expiration absolute lifetime 3600 / inactivity 900 sec

are these the correct settings?

with these setting sometimes I get:  
`The access token expired and a refresh token is not available. The user will need to sign in again.`

many thanks  
Francesco

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 3, 2021, 12:54am UTC](https://community.auth0.com/t/nextjs-rolling-session/74163/3 "2021-12-03T00:54:01Z")

</div>

Hi @francesco.venica,

Thanks for reaching out to the Auth0 Community!

> [@francesco.venica](#):
>
> are these the correct settings?

Yes, these settings will accomplish what you seek. However, you’ll also need to set the _Token Expiration (Seconds)_ to 30 seconds in your API settings. See [Update Access Token Lifetime](https://auth0.com/docs/security/tokens/access-tokens/update-access-token-lifetime) for more details.

And in regards to the message you get, it’s referring to your Refresh Token Rotation expiry time. Because you’ve set the _reuse interval_ value to 120 seconds, you’ll encounter the scenario where the access token expires within 30seconds but cannot get another access token while it is within 120 seconds from when the access token was originally requested. Therefore, as you observed, you must wait out the remaining time before you are allowed to reuse the refresh token to obtain a new access token.

In this case, you’ll need to change the Refresh Token Rotation reuse interval value to 30 seconds. Once that’s complete, you should have a rolling session.

Please let me know if there are any questions or concerns. I’d be happy to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![francesco.venica](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/francesco.venica/32/13023_2.png) [@francesco.venica](https://community.auth0.com/u/francesco.venica)\
**Post date:** [December 3, 2021, 1:03am UTC](https://community.auth0.com/t/nextjs-rolling-session/74163/4 "2021-12-03T01:03:35Z")

</div>

Hello @rueben.tiow ,

thanks for the answer, I’ll try that solution, I have one more question, reading through issues/articles in the repo I read that the refresh token should used only with SPA app, and they suggest to add `offline_access` as scope and enable the `offline_access` in the api. which solution is better between these 2?

many thanks  
Francesco

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 3, 2021, 8:03pm UTC](https://community.auth0.com/t/nextjs-rolling-session/74163/5 "2021-12-03T20:03:20Z")

</div>

Hi @francesco.venica,

Thank you for your response.

> [@francesco.venica](#):
>
> which solution is better between these 2?

I believe in this case because you are using a regular web application with the Auth0 Next.js SDK, you’ll need to use the `offline_access` as a scope and enable `offline_access` in your API. This is the preferred approach.

Generally, the `Refresh Token Rotation` is used for maintaining sessions in SPAs because there isn’t a persistent storage mechanism to store long-lived refresh tokens securely. This is explained in greater detail in our [Refresh Token Rotation](https://auth0.com/docs/security/tokens/refresh-tokens/refresh-token-rotation#maintain-user-sessions-in-spas) documentation.

Hoped this helps!

Thank you.

---

<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:** [December 18, 2021, 8:03pm UTC](https://community.auth0.com/t/nextjs-rolling-session/74163/7 "2021-12-18T20:03:59Z")

</div>

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