nextauth custom adapter doesn't redirect on createUser
Unanswered
Silver cyprinid posted this in #help-forum
Silver cyprinidOP
Hey all, I'm using a very simple custom adapter and struggling to find in the source code what actually triggers the redirect to the callbackUrl on successful login.
Basically,
But if user does not exist, it returns false,
So if I am approaching this incorrectly, please let me know, but my question in summary is:
How do I redirect after successful
Basically,
getUserByAccount checks the userId returned from the oauth login, and if a matching user exists in my database, it returns the user object and I am magically redirected to the callbackUrl passed into my signInBut if user does not exist, it returns false,
createUser is automatically called, and it returns a user object. But instead of being magically redirected to the callbackUrl, my url just changes from localhost:3000 to localhost:3000/?callbackUrl=<my callback url>So if I am approaching this incorrectly, please let me know, but my question in summary is:
How do I redirect after successful
createUser??1 Reply
Silver cyprinidOP
Really hit a brickwall, so until I can find something better, I'm just using middleware to redirect to the callbackUrl if it appears as a param:
Works perfectly, but would love a cleaner solution.
export function middleware(req) {
const callbackUrl = req.nextUrl.searchParams.get('callbackUrl');
if (callbackUrl) return NextResponse.redirect(new URL(callbackUrl));
return null;
}Works perfectly, but would love a cleaner solution.