I need to handle multiple cases for redirecting users based on various fields and custom claims in the user token, which involves navigating through complex if/else blocks.
Let's consider a simpler example where I want to redirect the user to /email-verification
if the user.email_verified
value is false.
const afterCallback = async (req: any, session: any, state: any) => {
// const router = useRouter()
const res = new NextResponse()
if (session.user) {
// check email verification status
if (!session.user.email_verified) {
return Response.redirect(
"http://localhost:3000/auth/email-verification",
308 // test value
)
} else {
// Handling redirection with multi-level if-else blocks
}
return session
export const GET = handleAuth({
login: handleLogin({
returnTo: "/",
}),
callback: async (req: any, res: any) => {
const callback = await handleCallback(req, res, { afterCallback })
console.log("callback", callback)
return callback;
},
})
Despite setting the redirect status code to 308
, I always end up redirected to http://localhost:3000
without user data. Checking the callback constant reveals that its status is actually 302
instead of 308
as intended.