No payload for Access Token with @auth0/nextjs-auth0 version 4.4.2

So I have an API and an application both using Auth0, I know the application can successfully authenticate with the api when I use the test curl command to get the access token. However when I try to use a user’s access token I am not able to authenticate and get a token without a payload. Here are the details:

Version: “@auth0/nextjs-auth0”: “^4.4.2”

auth0.ts:

import { Auth0Client } from "@auth0/nextjs-auth0/server"

export const auth0 = new Auth0Client({
    enableAccessTokenEndpoint: true,
    authorizationParameters: {
        audience: "https://api.azuretestapp.com",
        scope: "profile email openid offline_access"
    }
});
export async function getAccessToken() {
    const session = await auth0.getSession();
    if (!session) {
        throw new Error('Session not found');
    }
    const token = session.tokenSet.accessToken;
    return token;
}

Based on my understanding of how this client version works (with limited examples in docs) this should work, however I don’t see what it wrong.

I also tried to use const accessToken = await getAccessToken() which worked in previous versions of the client, however I now get: ‘TypeError: Failed to parse URL from /auth/access-token’

What am I doing wrong?

So turns out the issue was not having the root layout wrap the body in the Auth0Provider. Once I added it as seen here it worked:

 return (
    <html lang="en">
      <head>
        <meta charSet="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      </head>
      <body
        className={`${inter.variable} antialiased relative min-h-screen`}
      >
        <Auth0Provider>
          <main>
            {children}
          </main>
        </Auth0Provider>
      </body>
    </html>
  );
}```

I was also able to use the same token to authenticate with my dotnet api
1 Like

Hi @paulr

Welcome to the Auth0 Community!

Thank you for sharing the solution with the rest of us!

If you have any other questions, you can always post again!

Kind Regards,
Nik