# How to decode tokens in v4 middleware

**URL:** <https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412>\
**Category:** Get Help\
**Tags:** sessions, access-token\
**Created:** [February 19, 2025, 8:39am UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412 "2025-02-19T08:39:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfranco](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dfranco/32/71426_2.png) [@dfranco](https://community.auth0.com/u/dfranco)\
**Post date:** [February 19, 2025, 8:39am UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/1 "2025-02-19T08:39:33Z")

</div>

Ready to post? 🔍 First, try searching for your answer.  
In v3 I was able to use jwt.decode and fetch the roles and permissions off my access token in the middleware, I’ve upgraded to v4 and i am not able to do that anymore. I believe I am getting a JWE instead now. Even though I don’t have encrypted tokens toggled on in the console for the API of my Nextjs application.

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [February 19, 2025, 4:03pm UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/3 "2025-02-19T16:03:14Z")

</div>

Hi @dfranco,

Welcome to the Auth0 Community!

This video might be of help.

[![](https://global.discourse-cdn.com/auth0/original/3X/6/b/6b16d168f6cc53b48b3a52119313b7537c01974b.jpeg "Why is my Access Token not a JWT? (Opaque Token) -- Auth0 Support") ](https://www.youtube.com/watch?v=HjbPRGlLiwM&t=10s)

Make sure you include the audience when you request the token.

If you have any other questions, feel free to let us know.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![dfranco](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dfranco/32/71426_2.png) [@dfranco](https://community.auth0.com/u/dfranco)\
**Post date:** [February 19, 2025, 4:32pm UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/4 "2025-02-19T16:32:01Z")

</div>

Is there an example for decoding the accessToken in the new middleware? You can get the access token like this  
const token = await auth0.getAccessToken() , but I run into the decoding issue even though I still have the AUTH0\_AUDIENCE ENV variable from v2

AUTH0\_AUDIENCE=  
AUTH0\_DOMAIN=  
AUTH0\_CLIENT\_ID=  
AUTH0\_CLIENT\_SECRET=  
APP\_BASE\_URL=  
AUTH0\_SECRET=

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [February 19, 2025, 8:30pm UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/5 "2025-02-19T20:30:24Z")

</div>

Make sure that the jwt library is up to date. You can find it in the following link:

> **[GitHub - auth0/jwt-decode: Decode JWT tokens; useful for browser...](https://github.com/auth0/jwt-decode)**
>
> Decode JWT tokens; useful for browser applications.

Here should be an example of how to use it:

> **[GitHub - auth0/jwt-decode: Decode JWT tokens; useful for browser...](https://github.com/auth0/jwt-decode?tab=readme-ov-file#getting-started)**
>
> Decode JWT tokens; useful for browser applications.

Let us know if this solves the issue.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![dfranco](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dfranco/32/71426_2.png) [@dfranco](https://community.auth0.com/u/dfranco)\
**Post date:** [February 20, 2025, 12:31am UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/6 "2025-02-20T00:31:28Z")

</div>

![image](https://global.discourse-cdn.com/auth0/original/3X/4/0/4006e74540a7e521da92ec0fc7e265604cc3eed0.png)  
I attempted the library above, and these are my token settings. It still seems like I’m receiving a non JWT token like below. Am I missing an env variable or missing a newer config needed to decrypt the accessToken received in the new v4 auth0/nextjs-auth0?

eyJhbGciOiJkaXIiLCJlbmLiOiJCMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9kZXYtcTUzYy11c28uYXV0aDAuY29tLyJ9…-Mf7jFo4Ly\_PUtG-.ImMEmG4v7Og  
5ZQAttZMjcsoeS3LBehH8qJhI\_sAIVa3KjFv\_b5q21gcZ6fbO1DtMoXJdxNuileeylsf3l2bRds6c-a5JzeKRl18Pggd0boRD6Q1cvSVmJx8eJa0m4sloLafKSNvfn1PsTgf1qMImk  
DTnZoglbm\_5eooUkZXrTXonBCSTaLaS9WBRHKzI\_\_9xxv4zeKavREzwd1ffP8-v65HUIiiaXwUwqMonl001Z9QZ4KKpAaTvQdmULI8RoYWP-QCPs6my0jZdZGB0uiTzfHycphzrmxY  
DLARk\_5-GBY4yTVVU2l1-hdvyp2c-shICYJ0CJ-8\_hOD87KIRh6C-O34Mpwj5UQjnd4BlzzxlSgGl37f9XUgQPVQVm1x5n3saVgZ-NTSscC6QbsGe3ZzWB4NcNA.gUyiwxvxoKW8Oq  
Rv2rRCsg

Thanks

---

<div class="post-metadata">

**Author:** ![dfranco](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dfranco/32/71426_2.png) [@dfranco](https://community.auth0.com/u/dfranco)\
**Post date:** [February 20, 2025, 1:41am UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/7 "2025-02-20T01:41:12Z")

</div>

I figured it out nvm! the migration guide v4 talks about audience being used now in the auth init

---

<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 6, 2025, 1:41am UTC](https://community.auth0.com/t/how-to-decode-tokens-in-v4-middleware/182412/8 "2025-03-06T01:41:13Z")

</div>

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