# How implement refresh token flow in NextJS SDK

**URL:** <https://community.auth0.com/t/how-implement-refresh-token-flow-in-nextjs-sdk/131965>\
**Category:** Dev to Dev Hub\
**Tags:** classic-universal-login-experience, login-experience\
**Created:** [April 14, 2024, 4:55pm UTC](https://community.auth0.com/t/how-implement-refresh-token-flow-in-nextjs-sdk/131965 "2024-04-14T16:55:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lagui2003](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lagui2003/32/52262_2.png) [@lagui2003](https://community.auth0.com/u/lagui2003)\
**Post date:** [April 14, 2024, 4:55pm UTC](https://community.auth0.com/t/how-implement-refresh-token-flow-in-nextjs-sdk/131965/1 "2024-04-14T16:55:49Z")

</div>

Hi, I am working in a APP with nextjs and auth0, I want to know about how the refresh tokens works, the official docs are not clear and dont bring code examples.

I am following the basic instructions that is enable refresh tokens in the auth dashboard and add the offline\_access in the scope of login, but I dont know what more to do.

Currently the middleware looks like this, but the validation is not working correctly because after 24 hours (1 day) the access token expires.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/0/004b4643f07a5e8e93d4375567a31b9589dffa49.png)

Can anyone explain what more config or logic I need to add or have a repository of code I can refer to?

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [March 18, 2025, 6:36pm UTC](https://community.auth0.com/t/how-implement-refresh-token-flow-in-nextjs-sdk/131965/2 "2025-03-18T18:36:35Z")

</div>

Hi @lagui2003

I am sorry about the late reply to your inquiry!

The refresh tokens should be handled by the SDK as long as you have them configured in your application.

To read more about using refresh tokens with the middleware, I would recommend to review the examples document available on the [Github page](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#middleware-2) since they state that:

> The `request` and `response` objects must be passed as a parameters to the `getAccessToken(request, response)` method when called from a middleware to ensure that the refreshed access token can be accessed within the same request.
> 
> If you are using the Pages Router and are calling the `getAccessToken` method in both the middleware and an API Route or `getServerSideProps`, it’s recommended to propagate the headers from the middleware, as shown below. This will ensure that calling `getAccessToken` in the API Route or `getServerSideProps` will not result in the access token being refreshed again.

If you have any other questions, feel free to leave a reply or post again on the community!

Kind Regards,  
Nik

---

<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:** [April 1, 2025, 6:37pm UTC](https://community.auth0.com/t/how-implement-refresh-token-flow-in-nextjs-sdk/131965/4 "2025-04-01T18:37:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [September 5, 2025, 8:37pm UTC](https://community.auth0.com/t/how-implement-refresh-token-flow-in-nextjs-sdk/131965/5 "2025-09-05T20:37:35Z")

</div>


