# AccessTokenError: The user does not have a valid access token

**URL:** <https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014>\
**Category:** Get Help\
**Created:** [December 17, 2020, 12:48pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014 "2020-12-17T12:48:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ibi/32/14946_2.png) [@ibi](https://community.auth0.com/u/ibi)\
**Post date:** [December 17, 2020, 12:48pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/1 "2020-12-17T12:48:57Z")

</div>

Hi all

I’m trying to call my external api in **my server side rendered page** , with an access\_token because access requires a certain scope.

```
const tokenCache = auth0.tokenCache(context.req, context.res);
const { accessToken } = await tokenCache.getAccessToken({
  scopes: ['read:messages']
});

todos = await axios.get("http://localhost:3010/api/private", {
  'Authorization' : `Bearer ${accessToken}`
})
  .then(response => todos = response.data)
  .catch(error => console.error(error));

```

I added audience in my initAuth file like here [The user does not have a valid access token via getAccessToken · Issue #90 · auth0/nextjs-auth0 · GitHub](https://github.com/auth0/nextjs-auth0/issues/90)  
The value of my audience is the same as it is in the API settings.

But I get the error in the title of this post…

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [December 17, 2020, 1:56pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/2 "2020-12-17T13:56:56Z")

</div>

Hi @ibi

The access token could be invalid for many reasons. Start by verifying the access token with [jwt.io](http://jwt.io), then take a look at the API code that validates the access token to see if you can determine what is failing.

John

---

<div class="post-metadata">

**Author:** ![ibi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ibi/32/14946_2.png) [@ibi](https://community.auth0.com/u/ibi)\
**Post date:** [December 17, 2020, 2:45pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/3 "2020-12-17T14:45:10Z")

</div>

const { accessToken } = await tokenCache.getAccessToken({  
scopes: [‘read:messages’]  
});

This line is failing. Before I can log a console statement, but afterwards it’s not possible because this throws the error. Do you know why maybe?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [December 18, 2020, 6:18pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/4 "2020-12-18T18:18:52Z")

</div>

What are in context.req and context.res?

John

---

<div class="post-metadata">

**Author:** ![ibi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ibi/32/14946_2.png) [@ibi](https://community.auth0.com/u/ibi)\
**Post date:** [December 18, 2020, 7:35pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/5 "2020-12-18T19:35:22Z")

</div>

Hi John,

Thanks for the reply. I took another approach and downloaded a nextjs boilerplate.  
Things work there with SSR, don’t know why it doesn’t here, so I don’t need the answer here anymore. Thanks anyways.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 21, 2020, 1:01pm UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/6 "2020-12-21T13:01:54Z")

</div>

Thanks for letting us know!

---

<div class="post-metadata">

**Author:** ![navaneeth](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/navaneeth/32/13118_2.png) [@navaneeth](https://community.auth0.com/u/navaneeth)\
**Post date:** [January 6, 2021, 11:16am UTC](https://community.auth0.com/t/accesstokenerror-the-user-does-not-have-a-valid-access-token/55014/7 "2021-01-06T11:16:06Z")

</div>

hi @ibi, I’m having the same issue. Which boilerplate did you use? And any chance you found the exact issue? I"m halfway through my project, moving to a new boilerplate will be a pain in the ass. Thanks in advance
