Next.js Discord

Discord Forum

How to configure redirects for Magic Link Authentication in auth.js v5

Unanswered
Rhinelander posted this in #help-forum
Open in Discord
Avatar
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 (/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",
  },

0 Replies