saas-js / saas-ui

The React component library for startups, built with Chakra UI.
https://saas-ui.dev
MIT License
1.23k stars 118 forks source link

SaasUiAuth Supabase password login redirect not working #209

Closed alexleetc28 closed 4 months ago

alexleetc28 commented 4 months ago

Description

When I use SaasUiAuth with Supabase for password login, I expect to be redirected after logging in, but instead, nothing happens.

I think the reason is that Supabase's signInWithPassword doesn't have a redirect option like OAuth login does. Therefore, I believe SaasUI needs to add handling for redirects for Supabase password login. Otherwise, the user will be stuck on the Auth page when using password login.

Ref:

Link to Reproduction

No response

Steps to reproduce

providers.tsx:

const authService = createAuthService(supabase, {
  loginOptions: {
    redirectTo: "/dashboard",
  },
});

export const RootProviders = ({ children }: { children: React.ReactNode }) => (
  <SaasProvider theme={theme}>
    <AuthProvider {...authService}>{children}</AuthProvider>
  </SaasProvider>
);

components/Auth/index.tsx:

<SaasUiAuth
  providers={{
    azure: {
      icon: FaMicrosoft,
      name: "Azure",
    },
  }}
  type="password"
  onError={(view, error) => {
    if (error)
      snackbar.error({
        title: error.message,
        variant: "left-accent",
        duration: 10000,
        isClosable: true,
      });
  }}
  redirectUrl={getAbsoluteUrl(redirectUrl)}
/>

Saas UI Version

2.8.2

Chakra UI Version

No response

Browser

No response

Operating System

Additional Information

No response

linear[bot] commented 4 months ago

SUI-420 SaasUiAuth Supabase password login redirect not working

Pagebakers commented 4 months ago

Thanks for your feedback!

This option might be a bit confusing, you might expect it to always redirect. But in case of password login it's the responsibility of the user to set it up.

You can use the onSuccess handler or check isAuthenticated in useEffect to redirect away from the login page ones a user is logged in.