2

Edit:I found the source of this issue. The redirectTo param of the Auth component works for OAuth providers, but does not work for email or magiclink. Does anyone know how to redirect users to a certain page when the user signs in with email while using the Auth UI component?

I am using the Supabase Auth UI component.

When a user signs in with Google, they are correctly redirected to http://localhost:3001/loginrouting/ as specified in the redirectTo field. However when the user logs in via email and pw, they are not redirected and remain on the http://localhost:3001/login/ page. I was able to confirm that the login request was successful when using email and pw. The only thing that is not working is the redirect.

See screen recording here: https://www.loom.com/share/f32306a460ad4704b07f7ff0f6fb061b

Email is enabled as an Auth Provider in my Supabase Authentication settings.

Code here:

import { useSupabaseClient } from "@supabase/auth-helpers-react";
import { Auth } from "@supabase/auth-ui-react";
import { ThemeSupa } from "@supabase/auth-ui-shared";

export default function LoginPage() {
  const supabase = useSupabaseClient();

  return (
    <div className="items-center justify-center mx-12 h-screen">
      <Auth
        redirectTo="http://localhost:3001/loginrouting"
        supabaseClient={supabase}
        appearance={{ theme: ThemeSupa }}
        theme="default"
        providers={["google"]}
      />
    </div>
  );
}
Sam Yoon
  • 53
  • 5

1 Answers1

1

The Auth UI redirectTo works for email/password signup, OAuth and Otp (magic link) login. It doesn't work for email/password signup when you have confirm email turned off because you get returned the session right away and it's up to you the application developer to handle the redirect in your framework or library that you are working in.

Andrew Smith
  • 1,224
  • 6
  • 9
  • Thank you-- that's very helpful. I've tried to implement an onAuthStateChange listener to handle the returned session when the user signs in/up with email+pw. As you mentioned, I have confirm email turned off. I noticed that the page redirects to the correct page for a fraction of a second and then redirects to "/" as was the case prior to the auth listener implementation. What is the cause here? – Sam Yoon Mar 31 '23 at 02:21
  • Apologies, I forgot to mention: I am using Next JS and the Javascript 2.0 library for Supabase. More broadly, do you have any suggestions for how to handle the returned session when the user signs in with email and pw? I have confirm email turned off. – Sam Yoon Mar 31 '23 at 02:23