Closed
Description
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
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
Metadata
Metadata
Assignees
Labels
No labels