# Issues with Auth0 NextJS Session Expiration

**URL:** <https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355>\
**Category:** Get Help\
**Tags:** sessions, logout\
**Created:** [November 12, 2024, 1:54pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355 "2024-11-12T13:54:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyler.heathcote](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tyler.heathcote/32/62127_2.png) [@tyler.heathcote](https://community.auth0.com/u/tyler.heathcote)\
**Post date:** [November 12, 2024, 1:54pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/1 "2024-11-12T13:54:05Z")

</div>

I am using Auth0 to manage authentication in a NextJS application, and I am having issues with the session expiration. I would like the session to expire and the user to be logged out after 15 minutes of inactivity, or whenever they close their browser, but no matter what settings I change within Auth0, I haven’t been able to achieve this behavior. Within the Auth0 tenant settings, I’ve changed the session policy to “Non-persistent” and I’ve set the idle session lifetime to 15 minutes. I’ve also set the maximum session lifetime to 1 hour, but this doesn’t seem to be having an effect either. Is there another setting that I could be missing?

Thanks!

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [November 12, 2024, 10:04pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/3 "2024-11-12T22:04:32Z")

</div>

Hi @tyler.heathcote,

Welcome to the Auth0 Community!

Can you try changing the Maximum Session Lifetime setting to 15 minutes and observe the result?

Setting the session policy to “Non-persistent” will ensure the session ends when the browser closes. Are you using refresh token rotation?

Session documentation that may prove useful:

- [Session Lifetime Limits](https://auth0.com/docs/manage-users/sessions/session-lifetime-limits)
- [Configure Session Lifetime Limits](https://auth0.com/docs/manage-users/sessions/configure-session-lifetime-settings)

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![tyler.heathcote](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tyler.heathcote/32/62127_2.png) [@tyler.heathcote](https://community.auth0.com/u/tyler.heathcote)\
**Post date:** [November 20, 2024, 4:16pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/4 "2024-11-20T16:16:00Z")

</div>

Hi Mary Beth,

Thanks for the response. I have set the session policy to “Non-persistent”, the idle session lifetime to 15 minutes, and the maximum session lifetime to 15 minutes. Still, I logged into my application yesterday, completely closed out of my browser, and when returning to my website today, the session persisted and I was still logged in.

I am not using refresh token rotation, and I have attached a screenshot of my current settings for id token expiration and refresh token expiration. Please let me know if you can provide any further assistance, thank you!

 ![image](https://global.discourse-cdn.com/auth0/original/3X/2/9/29a1a4ee22efb1ffc37ddc8c8dcab6663e0ca736.png)

---

<div class="post-metadata">

**Author:** ![tyler.heathcote](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tyler.heathcote/32/62127_2.png) [@tyler.heathcote](https://community.auth0.com/u/tyler.heathcote)\
**Post date:** [November 25, 2024, 3:04pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/5 "2024-11-25T15:04:59Z")

</div>

Hi @marybeth.hunter - can you please provide any further guidance?

Thank you,  
Tyler

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [December 2, 2024, 4:33pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/6 "2024-12-02T16:33:40Z")

</div>

Hi @tyler.heathcote,

Thank you for your replies, and I apologize for the delay. I’ve been out of the office.

Could you kindly take a look at this article: [Why Users Remain Logged In After the Inactivity Timeout](https://community.auth0.com/t/why-users-remain-logged-in-after-the-inactivity-timeout/87161)

Specifically regarding the examples with the browser. I believe the settings are all configured correctly, but the session is not being cleared.

I look forward to your reply!

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![tyler.heathcote](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tyler.heathcote/32/62127_2.png) [@tyler.heathcote](https://community.auth0.com/u/tyler.heathcote)\
**Post date:** [December 4, 2024, 2:49pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/7 "2024-12-04T14:49:17Z")

</div>

Hi @marybeth.hunter ,

Thanks for the response. I have reviewed the article that you linked, and I think you may be correct about the clearing of the session, but I am unsure how to configure this in my application.

I am using the Auth0 NextJS SDK, as directed in the quickstart guide. I’ve also tried adjusting the configuration within my application as shown below:

const auth0Config = {  
domain: process.env.AUTH0\_DOMAIN,  
clientId: process.env.AUTH0\_CLIENT\_ID,  
clientSecret: process.env.AUTH0\_CLIENT\_SECRET,  
baseURL: process.env.AUTH0\_BASE\_URL,  
session: {  
rolling: true,  
rollingDuration: 60,  
absoluteDuration: 120  
}  
};

const edgeAuth0 = initAuth0(auth0Config);

but when inspecting the appSession cookie in the browser, the cookie shows an expiration of 24 hours later, not 60 seconds as I would expect.

Thanks again for your help and look forward to your response!

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [December 9, 2024, 11:05pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/8 "2024-12-09T23:05:11Z")

</div>

Hi @tyler.heathcote,

I have been doing some digging into this and have found a few things that may be helpful!

Referencing this [Community article](https://community.auth0.com/t/extending-the-next-js-appsession-cookie/152310), there are session environmental variables you can set with Next.js. If you’d like to control the session expiry, set the `AUTH0_SESSION_ROLLING_DURATION` and `AUTH0_SESSION_ABSOLUTE_DURATION` environment variables: [ConfigParameters | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/types/config.ConfigParameters.html)

They should be specified in seconds. The rolling session expiry is how long the session is set to. When the user keeps active on the app, this session is extended until the absolute duration is exceeded.

This issue would also be worth bringing up in tomorrow’s [Next.js AMA](https://community.auth0.com/t/december-10-auth0-community-ask-me-anything-unlocking-the-power-of-the-auth0-and-next-js/152331)!

Best,

Mary Beth

---

<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 23, 2024, 11:05pm UTC](https://community.auth0.com/t/issues-with-auth0-nextjs-session-expiration/151355/9 "2024-12-23T23:05:58Z")

</div>

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