Next-auth.js: Redirect to custom URL after successful login.

Hey all, I'm trying to figure out how to redirect after a successful login to a custom url. Specifically, I want to point to localhost/home instead of just the default localhost. Thank you!
4 Replies
Codex
Codex5mo ago
You could probably force them out of it with a router.push("/home") not sure if its the best practice though
Wiznet
Wiznet5mo ago
yeah i could maybe do that on my base layout page..but was hoping i could control the callback flow a bit more as im just using their sign in page
Alky
Alky5mo ago
Can you show the code for what you are doing right and then explain what's the behavior you want? Because i didn't get it. Isn't just get the signIn response, check if it's succesful and then send the user to whatever URL you want? Something like this:
const loginAttempt = await signIn('credentials', { redirect: false, ...data });
if (loginAttempt?.error) // Handle Error
// customLogicAndPushToCustomURL();
const loginAttempt = await signIn('credentials', { redirect: false, ...data });
if (loginAttempt?.error) // Handle Error
// customLogicAndPushToCustomURL();
Or inside pages/api/auth/[...nextauth].js Change the redirect callback
Louis
Louis5mo ago
This response on stack overflow might be what you're looking for? https://stackoverflow.com/questions/66780188/how-to-return-a-page-when-login-is-success-in-nextauth
Stack Overflow
How to return a Page when login is success in NextAuth
I want to return to a specific page when the login is success for an example when a user provides the correct credentials they should be redirected to a specific page lets say dashboard.js instead of
Want results from more Discord servers?
Add your server
More Posts
I has a long-running server task. I want to update my db afterwards. It's on the edge.Should I use TRPC on the edge runtime or prisma or update by supabase db direct? what's the cleanestuseForm vs useFormState in Nextjs v14Im just trying to understand the use case for using the react hook useForm over the react-dom useForParsing JSON Into zod schema using OPENAI GPTI want to parse a JSON example https://store.steampowered.com/api/appdetails?appids=1702010 Into laT3 Stack - Connect to MongodbI'm quite new to using the T3 stack, I have an application that needs to connect to MongoDB (I'm usiA social media message Aggregator platformHello there! I'm working on developing an app that acts as a central hub for users to connect with How can I globally manage errors in tRPC ? Trying `redirect` in custom link does not seem to workI want to be able to redirect a user when they become unauthenticated. Someone else mentioned to creHow to authenticate users on a dynamic sudomain (next-auth)Hey ! Hope you're doing well, I'm working on a project and I try to implement authentication on multRun Both Node and Bun Apps In a TurborepoHello, I was wondering if it possible to run both bun and node apps within the same turbo repo. I tserverCallback failing, receiving error on uploadThe upload works and I can see the file in the uploadthing dashboard, but I am still getting this erUploadthing on sveltekitHello. I have the upload thing pro plan for a project i have in next, but now i’m building my portfo