-
Notifications
You must be signed in to change notification settings - Fork 371
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
Unable to navigate on afterCallback #1600
Labels
documentation
Improvements or additions to documentation
Comments
Hi @adminCitify - thanks for raising this. Will raise a PR to fix those docs, essentially you want something like: import {
handleAuth,
handleCallback,
AppRouteHandlerFnContext,
Session,
getSession,
AfterCallbackAppRoute
} from '@auth0/nextjs-auth0';
import { NextRequest, NextResponse } from 'next/server';
const afterCallback: AfterCallbackAppRoute = (req: NextRequest, session: Session) => {
if (session.user) {
return session;
}
};
export const GET = handleAuth({
async callback(req: NextRequest, ctx: AppRouteHandlerFnContext) {
const res = (await handleCallback(req, ctx, { afterCallback })) as NextResponse;
const session = await getSession(req, res);
if (session) {
return NextResponse.redirect(`${process.env.AUTH0_BASE_URL}/success`, res);
} else {
return NextResponse.redirect(`${process.env.AUTH0_BASE_URL}/fail`, res);
}
},
onError(req: Request, error: Error) {
console.error(error);
}
}); |
Worked, thanks! |
@adamjmcgrath kindly update the docs also for this https://auth0.github.io/nextjs-auth0/types/handlers_callback.AfterCallbackAppRoute.html it took me long to find this solution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checklist
Description
Hi!
(APP router) I've tried everything to be able to navigate on the afterCallback.
I tried:
from 'next/navigation';
redirect('/home')
as the docs suggest (https://auth0.github.io/nextjs-auth0/types/handlers_callback.AfterCallbackAppRoute.html) with no success.
I tried:
const url = request.nextUrl.clone();
url.pathname = '/home';
return NextResponse.redirect(url);
..and much more. Nothing works. Please help!
Reproduction
Trying login, and afterCallback is being called succesfsully, but unable to navigate.
Additional context
Im omitting some code before the navigation as it doesn't affect.
nextjs-auth0 version
3.3.0
Next.js version
14.0.1
Node.js version
20.4.0
The text was updated successfully, but these errors were encountered: