# getAccessToken() returns encrypted token

**URL:** <https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883>\
**Category:** Get Help\
**Tags:** jwt, api\
**Created:** [November 10, 2021, 6:23am UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883 "2021-11-10T06:23:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephsk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josephsk/32/32879_2.png) [@josephsk](https://community.auth0.com/u/josephsk)\
**Post date:** [November 10, 2021, 6:23am UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883/1 "2021-11-10T06:23:16Z")

</div>

- **Which SDK this is regarding:** “@auth0/nextjs-auth0”: “1.6.1”
- **Platform Version:** e.g. Node v14.17.5

Using the examples from

> <https://github.com/auth0/nextjs-auth0/blob/beta/EXAMPLES.md#access-an-external-api-from-an-api-route>

and [How to Authenticate with Next.js and Auth0: A Guide for Every Deployment Model](https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/)

I am able to setup a nextjs/react app, sign into auth0 and get tokens back.  
The issue I am having is when I call “getAccessToken()” in the api layer, the token returned seems to be encrypted (or at least not readable)  
for example,

ewogICJhbGciOiAiZGlyIiwKICAiZW5jIjogIkEyNTZHQ00iLAogICJpc3MiOiAiaHR0cHM6Ly9zb21lLnVzLmF1dGgwLmNvbS8iCn0=…qigMtSvaWPt1Xf0t.aei3MbDgoP028UyerpXPRRa\_yLsrZQjRzO4lmbctxcyZq0lDYXSIsLXKUBcxMaffxeayDm5XRv0N49MSLoVgaHwz-AnSqqczS51tUyn8o1shUCgVoRYsefEM4FwFHb7GE-TDGNSsojjjQtsNvANpkyxK87Kh0mzFpV6cCFrqEFGtxJdGVmzaGtVC\_3Cs18RgJEB9zPyACuigOmizSBG-8ORrz–xbe4-uufWzsNxcVC4od7EQB1\_QXMtXHRSMK07rC4SOaF3Rf3EqQ4muIAAa4jEgpfSz9AkqHRJEOJH4kiOota7\_rN-fckgV2vNOKJWQw0aMZLFBFWy42b08bnwM7xGiWM07\_WUhg8.IaTp46zPVmhM9c-\_T2fnqQ

Some code in pages/api/user.js

import { getAccessToken, withApiAuthRequired } from ‘@auth0/nextjs-auth0’;

export default withApiAuthRequired(async function users(req, res) {  
console.log(“getting users …”)  
try {  
const { accessToken } = await getAccessToken(req, res);  
console.log(“with access token …”, accessToken)  
const response = await fetch(`https://someapi.com/user`, {  
headers: {  
Authorization: `Bearer ${accessToken}`,  
‘Content-Type’: ‘application/json’  
},  
method: ‘GET’  
});  
console.log(‘getting json …’, response.status)  
let json = await response.json();  
console.log(“json”, json);  
res.status(response.status).json(json)  
} catch(error) {  
console.error(error)  
res.status(error.status || 500).end(error.message)  
}  
});

and then I attempt to call that with client side code in pages/users.js

import Link from ‘next/link’  
import useSWR from ‘swr’  
import { withPageAuthRequired } from ‘@auth0/nextjs-auth0’

const fetcher = url =\> fetch(url).then(r =\> r.json())

const Users = () =\> {  
const { users, error } = useSWR(‘/api/user’, fetcher)  
if (!Array.isArray(users)) {  
return (  
\<\>  
Home

Users (no array)
  
{JSON.stringify(users)}  
\</\>  
)  
}

```
return (
    <>
        <Link href="/">Home</Link><br />
        <div>Users</div>
        <ul>
            {users.map(d => (<li key={d.userId}>{d.name} {d.userId}</li>))}
        </ul>
    </>
)

```

}  
export const getServerSideProps = withPageAuthRequired();  
export default Users

---

<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:** [November 10, 2021, 1:44pm UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883/2 "2021-11-10T13:44:20Z")

</div>

Hey there!

In order to handle that most effectively can I ask you to raise it as a GitHub issue in the SDK repo so we can have that addressed directly with the SDK maintainers? Once you have a link to it make sure to share it here with us so we can ping them.

---

<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:** [November 12, 2021, 7:27am UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883/3 "2021-11-12T07:27:49Z")

</div>

Hey there!

Did you have a chance to open it?

---

<div class="post-metadata">

**Author:** ![josephsk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josephsk/32/32879_2.png) [@josephsk](https://community.auth0.com/u/josephsk)\
**Post date:** [November 14, 2021, 5:08am UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883/4 "2021-11-14T05:08:08Z")

</div>

> [@josephsk](#):
>
> import { getAccessToken, withApiAuthRequired } from ‘@auth0/nextjs-auth0’;
> 
> export default withApiAuthRequired(async function users(req, res) {  
> console.log(“getting users …”)  
> try {  
> const { accessToken } = await getAccessToken(req, res);  
> console.log(“with access token …”, accessToken)

Sorry for the delay – and the skimpy description – See [I am getting encrpted cookie when asking for access token · Issue #537 · auth0/nextjs-auth0 · GitHub](https://github.com/auth0/nextjs-auth0/issues/537)  
And thanks for your follow up

---

<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:** [November 15, 2021, 8:12am UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883/5 "2021-11-15T08:12:41Z")

</div>

No worries!

Thanks for creating the issue, I’ll ping the repo maintainers in a few minutes!

---

<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:** [November 25, 2021, 12:37pm UTC](https://community.auth0.com/t/getaccesstoken-returns-encrypted-token/72883/6 "2021-11-25T12:37:25Z")

</div>


