Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get JWT for user #1984

Open
6 tasks done
Azer0s opened this issue Mar 20, 2025 · 0 comments
Open
6 tasks done

Can't get JWT for user #1984

Azer0s opened this issue Mar 20, 2025 · 0 comments

Comments

@Azer0s
Copy link

Azer0s commented Mar 20, 2025

Checklist

Description

I am currently trying to get the JWT for a user to later use against a Java Spring backend but unfortunately, nothing has worked so far.

export default async function RootLayout({
  children,
}: Readonly<{ children: React.ReactNode }>) {
  let session: SessionData | null = null;
  try {
    session = await auth0.getSession();

    const { token } = await getAccessToken();
    console.log(token);
  } catch (err) {
    void err;
  }
...

This always causes the following error:

[TypeError: Failed to parse URL from /auth/access-token] {
  [cause]: [TypeError: Invalid URL] {
    code: 'ERR_INVALID_URL',
    input: '/auth/access-token'
  }
}

When I tried manually getting the token via fetch like so

export default async function RootLayout({
  children,
}: Readonly<{ children: React.ReactNode }>) {
  let session: SessionData | null = null;
  try {
    session = await auth0.getSession();

    const host = (await headers()).get("host");

    const tokenRes = await fetch(`http://${host}/auth/access-token`).then(
      (res) => res.json()
    );
    console.log(tokenRes);
  } catch (err) {
    void err;
  }
...

I get another error message telling me that the user does not have an active session.

{
  error: {
    message: 'The user does not have an active session.',
    code: 'missing_session'
  }
}

Reproduction

As seen above

Additional context

I can get the session with await auth0.getSession() but when I try to access the token, I get a JWE instead of a JWT. The AUTH0_AUDIENCE is set in my .env.local file.

nextjs-auth0 version

^4.0.3

Next.js version

15.2.1

Node.js version

23.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant