supabase icon indicating copy to clipboard operation
supabase copied to clipboard

onAuthStateChange only fires "INITIAL_SESSION" event?

Open tedik123 opened this issue 6 months ago • 0 comments

Hello I'm not sure what I'm doing wrong because this setup worked on another project a bit ago but onAuthStateChange does not fire besides the initial session event. I believe I am successfully logging in with google OAuth because it does redirect me back to localhost and if I read the session data I have my tokens and basic google account info. Sign in only fires if I am signed in and then I switch tabs and back to it, but not when I actually log in. This is all inside a userStore using pinia and the userStore is always on the page. Any idea what I'm doing wrong?

const supabase = useSupabaseClient()
// use google oAuth
async function handleLogin() {
       await supabase.auth.signInWithOAuth({
                provider: 'google',
       })
}

supabase.auth.onAuthStateChange(async (event, session) => {
        console.log('event', event)
        switch (event) {
            case "INITIAL_SESSION":
                console.log("Initial session", session)
                break
            case 'SIGNED_IN':
                console.log('User signed in');
                await handleSignInEvent()
                break;
            
        }
 });

tedik123 avatar Feb 04 '24 18:02 tedik123