# The Access Token Obtained with nextjs-auth0 v4 Beta Is Different

**URL:** <https://community.auth0.com/t/the-access-token-obtained-with-nextjs-auth0-v4-beta-is-different/169484>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [January 21, 2025, 2:51am UTC](https://community.auth0.com/t/the-access-token-obtained-with-nextjs-auth0-v4-beta-is-different/169484 "2025-01-21T02:51:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiroyuki.sakuraba](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hiroyuki.sakuraba/32/71084_2.png) [@hiroyuki.sakuraba](https://community.auth0.com/u/hiroyuki.sakuraba)\
**Post date:** [January 21, 2025, 2:51am UTC](https://community.auth0.com/t/the-access-token-obtained-with-nextjs-auth0-v4-beta-is-different/169484/1 "2025-01-21T02:51:21Z")

</div>

I updated Next.js to v15 and also updated nextjs-auth0 to v4 Beta. I noticed that, for the same user, the access token retrieved by nextjs-auth0 v3 is different from the one retrieved by v4 Beta.

Below are the methods used to obtain the access token in the Next.js middleware.

v3

```auto
import {getSession} from "@auth0/nextjs-auth0/edge";
export default async function middleware(
  request: NextRequest,
  event: NextFetchEvent,
) {
  const response = NextResponse.next();
  const session = await getSession(request, response);
}

```

v4

```auto
import { auth0 } from "./utils/auth0";
export async function middleware(request: NextRequest) {
  const authResponse = await auth0.middleware(request);
  const accessToken = await auth0.getAccessToken(request, authResponse);
}

```

When I verify the access token obtained with v4 using the jose library, I get the following error:

JWSInvalid: Invalid Compact JWS

```auto
import { createRemoteJWKSet, jwtVerify } from "jose";

const JWKS = createRemoteJWKSet(
  new URL(`https://${env.AUTH0_DOMAIN}/.well-known/jwks.json`),
);

const { payload } = await jwtVerify(jwt, JWKS, {
  issuer: `https://${env.AUTH0_DOMAIN}/`,
  audience: env.AUTH0_AUDIENCE,
});

```

Do you have any advice or suggestions on how to resolve this issue?

---

<div class="post-metadata">

**Author:** ![hiroyuki.sakuraba](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hiroyuki.sakuraba/32/71084_2.png) [@hiroyuki.sakuraba](https://community.auth0.com/u/hiroyuki.sakuraba)\
**Post date:** [January 21, 2025, 3:45am UTC](https://community.auth0.com/t/the-access-token-obtained-with-nextjs-auth0-v4-beta-is-different/169484/2 "2025-01-21T03:45:52Z")

</div>

When I specified the scope and audience, I started receiving the same access token as I did in v3.

```auto
export const auth0 = new Auth0Client({
  authorizationParameters: {
    scope: "openid profile",
    audience: "http://localhost:3000",
  },
});

```

The issue is resolved, but I still don’t fully understand the reason behind it.

---

<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 11, 2025, 7:32pm UTC](https://community.auth0.com/t/the-access-token-obtained-with-nextjs-auth0-v4-beta-is-different/169484/3 "2025-03-11T19:32:45Z")

</div>

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