# How to resolve: "The access token expired and a refresh token is not available."

**URL:** <https://community.auth0.com/t/how-to-resolve-the-access-token-expired-and-a-refresh-token-is-not-available/139278>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, nextjs-auth0\
**Created:** [July 19, 2024, 3:10am UTC](https://community.auth0.com/t/how-to-resolve-the-access-token-expired-and-a-refresh-token-is-not-available/139278 "2024-07-19T03:10:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KevinM](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kevinm/32/55831_2.png) [@KevinM](https://community.auth0.com/u/KevinM)\
**Post date:** [July 19, 2024, 3:10am UTC](https://community.auth0.com/t/how-to-resolve-the-access-token-expired-and-a-refresh-token-is-not-available/139278/1 "2024-07-19T03:10:30Z")

</div>

I have a NextJS app router as my frontend, and an express API backend. Everything is going smoothly, I can get an access token in my nextJS client and send that to my express API for route protection.

However I’m noticing that if I stay logged in long enough my nextJS client returns `The access token expired and a refresh token is not available.`. What should I look at to manage refreshing my accessToken? Is there a simple way to automate this? I’ve looked at this error in other threads/topics but aren’t able to sort out what I’m missing.

Below is where I’m getting my accessToken from the sdk and executing a request.

```auto
import { redirect } from 'next/navigation';

import { getAccessToken } from '@auth0/nextjs-auth0';

const apiServerUrl = process.env.API_SERVER_URL;

export default async function HomePage() {

  const { accessToken } = await getAccessToken();

  const response = await fetch(`${apiServerUrl}/protected/accountId`, {
    headers: {
      'content-type': 'application/json',
      Authorization: `Bearer ${accessToken}`,
    },
  });

  const responseData = await response.json();
  const accountId = responseData.accountId;

  redirect(`/${accountId}`);

  return null; 
}

```

I do see `getAccessTokenSilently` is available in the react SDK, is that something I should switch to, or is there a way to do this with the nextjs sdk?

EDIT:

It looks like adding the following to my .env file automates fetching a new access token?

```auto
AUTH0_SCOPE='openid offline_access'

```

Am I right in assuming that I can be hands off of managing the refreshing of tokens with this? Here is my app/api/auth/[auth0]/route.js

```auto
import { handleAuth } from '@auth0/nextjs-auth0';

export const GET = handleAuth();

```

---

<div class="post-metadata">

**Author:** ![juan.justpaid](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/juan.justpaid/32/49123_2.png) [@juan.justpaid](https://community.auth0.com/u/juan.justpaid)\
**Post date:** [November 15, 2024, 7:57pm UTC](https://community.auth0.com/t/how-to-resolve-the-access-token-expired-and-a-refresh-token-is-not-available/139278/2 "2024-11-15T19:57:14Z")

</div>

did you find a solution for this? experiencing the same issue right now

---

<div class="post-metadata">

**Author:** ![alex.brett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alex.brett/32/60157_2.png) [@alex.brett](https://community.auth0.com/u/alex.brett)\
**Post date:** [November 15, 2024, 11:49pm UTC](https://community.auth0.com/t/how-to-resolve-the-access-token-expired-and-a-refresh-token-is-not-available/139278/3 "2024-11-15T23:49:39Z")

</div>

Hello @KevinM!

I found a good community article for you that should clear up on using refresh tokens.

> [@How to use the refresh token with @auth0/nextjs-auth0](https://community.auth0.com/t/how-to-use-the-refresh-token-with-auth0-nextjs-auth0/126612):
>
> 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?

I hope this helps!

Best,  
Alex

---

<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 3, 2024, 12:22am UTC](https://community.auth0.com/t/how-to-resolve-the-access-token-expired-and-a-refresh-token-is-not-available/139278/5 "2024-12-03T00:22:09Z")

</div>

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