How to configure redirects for Magic Link Authentication in auth.js v5
Unanswered
Rhinelander posted this in #help-forum
RhinelanderOP
I have a registration and login page setup, and I want to control the page each redirects to:
Login Page: After a successful login, I want users to be redirected to the community page (
Register Page: After registration, users should be directed to a new community page (
Since this process uses a magic link for authentication, there is an intermediate step:
After users click the magic link in their email, they are temporarily directed to a verification page (
Currently, after verification, they are redirected to the home page by default, but I want it to go:
To
To
This is my register code.
And this is my auth.ts config for pages
Login Page: After a successful login, I want users to be redirected to the community page (
/c
).Register Page: After registration, users should be directed to a new community page (
/new-community
).Since this process uses a magic link for authentication, there is an intermediate step:
After users click the magic link in their email, they are temporarily directed to a verification page (
/auth/verify
).Currently, after verification, they are redirected to the home page by default, but I want it to go:
To
/c
if they are logging in.To
/new
-community if they are registering.This is my register code.
async function onSubmit(values: RegisterSchema) {
const register = await registerUser(values);
if (register.success) {
await signIn("resend", {
email: values.email,
});
} else {
form.setError("root", { message: register.message });
}
}
And this is my auth.ts config for pages
pages: {
error: "/auth/error",
verifyRequest: "/auth/verify",
signIn: "/c",
signOut: "/login",
newUser: "/new-community",
},