# How to refresh an access token in a Next.js application?

**URL:** <https://community.auth0.com/t/how-to-refresh-an-access-token-in-a-next-js-application/75806>\
**Category:** Get Help\
**Tags:** refresh\_token, refresh-tokens, access-token, refresh-token, nextjs\
**Created:** [January 4, 2022, 5:20pm UTC](https://community.auth0.com/t/how-to-refresh-an-access-token-in-a-next-js-application/75806 "2022-01-04T17:20:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![will.dev8787](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/will.dev8787/32/33959_2.png) [@will.dev8787](https://community.auth0.com/u/will.dev8787)\
**Post date:** [January 4, 2022, 5:20pm UTC](https://community.auth0.com/t/how-to-refresh-an-access-token-in-a-next-js-application/75806/1 "2022-01-04T17:20:43Z")

</div>

Found [this](https://community.auth0.com/t/update-spa-token-after-user-updates-profile-through-managementapi-without-new-login/74166) question which asks about exactly the same problem:

1. user logs in (frontend application gets an `access_token`);
2. user updates its profile, frontend sends information to the backend, backend calls the `Management API`
3. user’s `access_token` is now **out of date** on the frontend;
4. we want it to be up to date;

- read [this](https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/) tutorial - mentions that `refresh_token` exists but doesn’t show how to implement them.

- read [this](https://auth0.com/docs/security/tokens/refresh-tokens) tutorial - it says that SPA applications should use the \*\* Authorization Code Flow with Proof Key for Code Exchange (PKCE)\*\* along with **Refresh Token Rotation**

- read [this](https://auth0.com/docs/security/tokens/refresh-tokens/configure-refresh-token-expiration) and configured the refresh token rotation in my application;

- read [this](https://auth0.com/docs/authorization/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce) to understand and implement **Authorization Code Flow with PKCE** - and this content led me to look for tutorials for SPA applications;

- read [this](https://auth0.com/docs/quickstart/spa/react) and this is where it really frustrated me. There is **no example** of how to do the refresh token rotation along with the Authorization Code Flow with PKCE in these quickstarts.

Watched the videos in Auth0’s YouTube channel and re-read the Next.js tutorial a few times.

Can someone, please tell me. In a Next.js application, how do I refresh my user’s `access_token` to reflect the latest information on his profile without asking him to login again?

---

<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:** [January 4, 2022, 9:20pm UTC](https://community.auth0.com/t/how-to-refresh-an-access-token-in-a-next-js-application/75806/3 "2022-01-04T21:20:49Z")

</div>

Hi @will.dev8787,

Welcome to the Auth0 Community!

First, I would like to clarify that the Auth0 Next.js SDK is a Regular Web App instead of a Single Page Application (SPA).

With that said, you will still want to use the refresh\_token to refresh the access token of the user. To do so, you will need to specify the `scope=offline_access` in the `/authorize` request to [Get Refresh Tokens](https://auth0.com/docs/security/tokens/refresh-tokens/get-refresh-tokens).

```auto
https://YOUR_DOMAIN/authorize?
    audience=API_AUDIENCE&
    scope=offline_access&
    response_type=code&
    client_id=YOUR_CLIENT_ID&
    redirect_uri=https://YOUR_APP/callback&
    state=OPAQUE_VALUE

```

After this is complete, you can use that refresh token to get a new access token.

> **[Use Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens)**
>
> Describes how to use a Refresh Token you received during authorization.

Please let me know if you have any further questions.

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:** [January 19, 2022, 9:21pm UTC](https://community.auth0.com/t/how-to-refresh-an-access-token-in-a-next-js-application/75806/4 "2022-01-19T21:21:17Z")

</div>

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