# How to use the refresh token with @auth0/nextjs-auth0

**URL:** <https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [February 6, 2024, 11:40am UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612 "2024-02-06T11:40:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![me1k](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/me1k/32/54262_2.png) [@me1k](https://community.auth0.com/u/me1k)\
**Post date:** [February 6, 2024, 11:40am UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/1 "2024-02-06T11:40:34Z")

</div>

Hi there,

basically my question is, how to use the refresh\_token with the @auth0/nextjs-auth0 sdk?

Do i need to implement a whole new request like in this documentation:

[Use Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens) ? Or is there a function withing the sdk?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 6, 2024, 5:26pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/3 "2024-02-06T17:26:23Z")

</div>

Hey @me1k !

> [@me1k](#):
>
> Do i need to implement a whole new request like in this documentation:
> 
> [Use Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens) ? Or is there a function withing the sdk?

You can get/use refresh tokens using the SDK directly (plus a couple tenant settings) - Please see here:

> <https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#getting-a-refresh-token>

---

<div class="post-metadata">

**Author:** ![me1k](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/me1k/32/54262_2.png) [@me1k](https://community.auth0.com/u/me1k)\
**Post date:** [February 6, 2024, 6:43pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/4 "2024-02-06T18:43:27Z")

</div>

Hmm and what bulletpoint do you refer to exactly? I guess `Create your own instance of the SDK` ?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 6, 2024, 6:52pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/5 "2024-02-06T18:52:54Z")

</div>

The link should point to [getting a refresh token](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#getting-a-refresh-token).

---

<div class="post-metadata">

**Author:** ![me1k](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/me1k/32/54262_2.png) [@me1k](https://community.auth0.com/u/me1k)\
**Post date:** [February 6, 2024, 7:07pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/6 "2024-02-06T19:07:36Z")

</div>

But then i dont understand it. I already get a refresh token. But i wondered, if there is a built in way of the SDK to use the refresh token, to get a new access token/token id

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 6, 2024, 7:37pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/7 "2024-02-06T19:37:05Z")

</div>

Ahh gotcha - Assuming you’ve configured your application and dashboard correctly (outlined in the steps linked) the SDK should handle refreshing the token for you.

---

<div class="post-metadata">

**Author:** ![me1k](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/me1k/32/54262_2.png) [@me1k](https://community.auth0.com/u/me1k)\
**Post date:** [February 7, 2024, 6:47am UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/8 "2024-02-07T06:47:36Z")

</div>

But i somehow need to know this in the Frontend, right? So i after my first login i request an accessToken/idToken and after 5mins i want fetch a new token with my refreshToken … and i wonder, if there is a built in way from the SDK or if i need to handle this on my own.

Because here it says, i need to do a extra request on my own to get a new token:  
[https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens)

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 12, 2024, 11:44pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/9 "2024-02-12T23:44:29Z")

</div>

Hey @me1k sorry for the delayed response here - According to the docs [here](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#access-an-external-api-from-an-api-route) specifically for `withApiAuthRequired` calling `getAccessToken` will result in a refreshed access token if it’s expired and assuming you have a valid refresh token.

---

<div class="post-metadata">

**Author:** ![momar.hughes](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@momar.hughes](https://community.auth0.com/u/momar.hughes)\
**Post date:** [February 14, 2024, 7:31am UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/10 "2024-02-14T07:31:44Z")

</div>

does the `getSession` function refresh the access token or is it only the `getAccessToken` that does that?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 15, 2024, 4:15pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/11 "2024-02-15T16:15:11Z")

</div>

Only `getAccessToken` will renew tokens with a valid refresh token.

---

<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:** [March 18, 2024, 10:42pm UTC](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612/12 "2024-03-18T22:42:22Z")

</div>

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