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

Version 4.1 Error in onCallback of lib/auth0.ts not work #1976

Open
6 tasks done
NguyenCao-Glams opened this issue Mar 19, 2025 · 0 comments
Open
6 tasks done

Version 4.1 Error in onCallback of lib/auth0.ts not work #1976

NguyenCao-Glams opened this issue Mar 19, 2025 · 0 comments

Comments

@NguyenCao-Glams
Copy link

NguyenCao-Glams commented Mar 19, 2025

Checklist

Description

I try to process error when initialize auth0, but the an error is show instead of redirect to error page

Image

Reproduction

In file lib/auth0.ts, add

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

export const auth0 = new Auth0Client({
  authorizationParameters: {
    audience: process.env.AUTH0_AUDIENCE,
    scope: 'asd'
  },

  async onCallback(error, context, session) {
    // redirect the user to a custom error page
    if (error) {
      return NextResponse.redirect(
        new URL(`/error?error=${error.message}`, process.env.APP_BASE_URL)
      )
    }

    // complete the redirect to the provided returnTo URL
    return NextResponse.redirect(
      new URL(context.returnTo || '/', process.env.APP_BASE_URL)
    )
  }
})

It will not redirect to error page, but show an error window

Additional context

No response

nextjs-auth0 version

4.1

Next.js version

15.1.7

Node.js version

22.14.0

@NguyenCao-Glams NguyenCao-Glams changed the title Error in onCallback of lib/auth0.ts not work Version 4.1 Error in onCallback of lib/auth0.ts not work Mar 20, 2025
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