Skip to content

Can't get ididToken on v4 version #1840

Closed
@psycpvv

Description

@psycpvv

Checklist

Description

In our project, we have to get idToken for token trading.

This is v3 code. As you can see, I could get idToken from session object.

import { NextResponse } from 'next/server'

import auth0 from '@/config/auth0'

export const GET = auth0.withApiAuthRequired(async function GET(req) {
  const res = new NextResponse()
  try {
    const session = await auth0.getSession(req, res)
    const user = session?.user
    if (!user?.email_verified)
      return NextResponse.json(
        { error: 'email is not verified' },
        { status: 400 },
      )
    return NextResponse.json(
      { idToken: session?.idToken, user: session?.user },
      res,
    )
  } catch (error: any) {
    return NextResponse.json(
      { error: error.message },
      { status: error.status || 500 },
    )
  }
})

But idToken doesn't exist in the session object of v4.

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

import { BASE_URL } from '@/constants/constants'

export const auth0 = new Auth0Client({
  appBaseUrl: BASE_URL,
  authorizationParameters: {
    scope: 'openid profile email read:products offline_access',
  },
})

Already openid is added on scope.
Help me pls.

Reproduction

const session = await auth0.getSession()
console.log(session?.idToken)
// undefined

I think, it's enough to explain.

Additional context

No response

nextjs-auth0 version

4.0.0-beta.9

Next.js version

15.0.4

Node.js version

v22.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions