# How to set up the Audience in Next.js SDK to get a valid JWT?

**URL:** <https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [February 3, 2024, 11:40am UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438 "2024-02-03T11:40:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raph1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raph1/32/49678_2.png) [@raph1](https://community.auth0.com/u/raph1)\
**Post date:** [February 3, 2024, 11:40am UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438/1 "2024-02-03T11:40:01Z")

</div>

Hi,

I’m moving our App from React to Next.js, everything worked fine with the React SDK. But now, using the Next.js SDK I’m not able to get a valid JWT, just getting an opaque token…

I’m trying to find a way to set the Audience during Login to get a valid JWT, like I did in React, but can’t find how to do that.

Even in the doc for authorizationParams, there is no audience params… [AuthorizationParams | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/interfaces/handlers_login.AuthorizationParams.html)

Can someone help me with this ?

Many thanks.

---

<div class="post-metadata">

**Author:** ![raph1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raph1/32/49678_2.png) [@raph1](https://community.auth0.com/u/raph1)\
**Post date:** [February 5, 2024, 1:52pm UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438/2 "2024-02-05T13:52:30Z")

</div>

I also added AUTH0\_AUDIENCE to the .env.local with the other params but that seems to be ignored…

Does anyone know about that issue ?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 5, 2024, 7:24pm UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438/4 "2024-02-05T19:24:26Z")

</div>

Hey @raph1 welcome to the community!

> [@raph1](#):
>
> Even in the doc for authorizationParams, there is no audience params… [AuthorizationParams | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/interfaces/handlers_login.AuthorizationParams.html)

Hmm thanks for pointing this out - The audience param should indeed be added to `AuthorizationParams`:

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

---

<div class="post-metadata">

**Author:** ![raph1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raph1/32/49678_2.png) [@raph1](https://community.auth0.com/u/raph1)\
**Post date:** [February 7, 2024, 10:22am UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438/5 "2024-02-07T10:22:22Z")

</div>

@ty.frith Thanks for you reply.

I was finally able to get a valid JWT token by passing manually the audience to in the AuthorizationParams.

But now I have another issue… This JWT is NOT recognized as a valid token by my Flask Server.

It was working perfectly well (and still works) with my React Client. The setup is the same, same audience etc… when I look inside the JWT token with [jwt.io](http://jwt.io) I find the same informations…

But for some reason the Token received in my Next.js app isn’t accepted by my server while the token received in my React App is accepted.

Any idea of what’s going on ?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 10, 2024, 1:37am UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438/6 "2024-02-10T01:37:03Z")

</div>

> [@raph1](#):
>
> I was finally able to get a valid JWT token by passing manually the audience to in the AuthorizationParams.

That’s great, thanks for confirming!

> [@raph1](#):
>
> It was working perfectly well (and still works) with my React Client. The setup is the same, same audience etc… when I look inside the JWT token with [jwt.io](http://jwt.io) I find the same informations…
> 
> But for some reason the Token received in my Next.js app isn’t accepted by my server while the token received in my React App is accepted.

Very odd! Is your Flask server throwing any error in particular when attempting to verify the token?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 27, 2024, 12:11am UTC](https://community.auth0.com/t/how-to-set-up-the-audience-in-next-js-sdk-to-get-a-valid-jwt/126438/7 "2024-02-27T00:11:22Z")

</div>


