nuxt-modules / supabase

Supabase module for Nuxt.
https://supabase.nuxtjs.org
MIT License
733 stars 129 forks source link

onAuthStateChange only fires "INITIAL_SESSION" event? #330

Open tedik123 opened 9 months ago

tedik123 commented 9 months ago

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;

        }
 });