Next.js Discord

Discord Forum

Fail redirect with callbackUrl next-auth

Answered
Kerry Blue Terrier posted this in #help-forum
Open in Discord
Avatar
Kerry Blue TerrierOP
Hello everyone!

My next-auth signIn is redirecting to:
http://localhost:3000/?callbackUrl=https%3A%2F%2F127.0.0.1%3A3000%2Fdashboard.

Does anyone know why this callbackUrl is within of the URL and how to solve it?
Answered by B33fb0n3
if you don't use the pre build site from next-auth, you need to handle the callback url yourself. You can get it clientside by using useSearchParams and then redirect with the router to the specific url
View full answer

6 Replies

Avatar
it's inside the url so your app knows where to redirect the person after a sign in response. It shows where the user comes from to redirect him back after everything is done
Avatar
Kerry Blue TerrierOP
But it didn't work, url change from http://localhost:3000 to http://localhost:3000/?callbackUrl=https%3A%2F%2F127.0.0.1%3A3000%2Fdashboard but page stay at SignIn Page.

Any suggestions, please?
Avatar
if you don't use the pre build site from next-auth, you need to handle the callback url yourself. You can get it clientside by using useSearchParams and then redirect with the router to the specific url
Answer
Avatar
Kerry Blue TerrierOP
It solved my problem, thanks a lot.
Avatar
Happy to help