© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
Ricardo de Paula

Issues with Login Conditional Using Supabase and React

I'm encountering an issue with a login component in a React project using Supabase for authentication. The login flow seems to function, but I'm having trouble with a specific conditional that's supposed to redirect the user to the dashboard after successful login.

Here's the relevant code snippet:

const { supabase, session } = useContext(SupabaseContext)
const { supabase, session } = useContext(SupabaseContext)


const handleLogin = () => {
  supabase.auth
    .signInWithOAuth({ provider: 'google' })
    .then(({ data, error }) => {
      console.log(data, error);
      if (data && session && session.access_token) {
        navigate('/dashboard');
      } else {
        console.log('Login failed, no user data.');
      }
    })
    .catch((err) => {
      console.error('Error during login:', err);
    });
};
const handleLogin = () => {
  supabase.auth
    .signInWithOAuth({ provider: 'google' })
    .then(({ data, error }) => {
      console.log(data, error);
      if (data && session && session.access_token) {
        navigate('/dashboard');
      } else {
        console.log('Login failed, no user data.');
      }
    })
    .catch((err) => {
      console.error('Error during login:', err);
    });
};


The issue arises with the conditional if (data && session && session.access_token). After "successfully" logging in with Google, I am unexpectedly redirected first to the '/dashboard' and then immediately to the home page, instead of staying on the dashboard. This behavior seems inconsistent with the intended functionality of the conditional statement.

I set up a redirect in Supabase but it didn't work.
image.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Using supabase and React Query
SupabaseSSupabase / help-and-questions
4y ago
Supabase Dashboard login issues
SupabaseSSupabase / help-and-questions
4mo ago
Need Help with Vitest Login and Authorization Token using Supabase
SupabaseSSupabase / help-and-questions
3y ago
React Native Expo Supabase Realtime Issues
SupabaseSSupabase / help-and-questions
14mo ago