Hello,
I faced the same problem trying to get the access token from the app router.
-
As of now, @auth0/nextjs-auth0 does not support getAccessToken() in App Router route handlers because it requires Node.js req/res.
-
You would need to keep your token API route in the Pages Router, or
Do this:
app/api/auth/token/route.ts
import { auth0 } from "@/lib/auth0";
import { NextResponse, NextRequest } from "next/server";
export async function GET(req: NextRequest) {
const session = await auth0.getSession();
return NextResponse.json({ accessToken: session?.tokenSet.accessToken });
}
Notice that the accessToken is a property, not a function.