2

im practicing authentication at the moment with sveltekit and Supabase

RLS is on and one of the issues im having is after i log out, and i sign in with another email, i can see the info from the previous session and when i hard refresh, then i see the correct data. Im not sure how to fix this

in my store


export const user = readable(null, (set) => {
    set(supabase.auth.user());
    const unsubscribe = supabase.auth.onAuthStateChange((_, session) => {
        session ? set(session.user) : set(null);
    });
    return () => {
        unsubscribe.data.unsubscribe();
    };
});

2 Answers2

1

I currently have a similar problem. Where after sign out, still the old user persists somehow.

My auth is only on the clientside. I use sveltekit (as a static site generator)

after signOut() there is still the sb-refresh-token cookie and the sb-access-token cookie with the jwt thus, supabase.auth.getUser() still gets me the (old)user

so user does not get logged out.

what helped me is to reload the page after the signout()

aka not use the linking and goto() function of my framework but rather use the browser function

window.location.href = '/loggedOut';

This deleted the cookies for me

1

If you're using Supabase Svelte auth helpers you can use invalidate("supabase:auth") right after calling supabase.auth.signOut()

import { invalidate } from "$app/navigation";
...
invalidate("supabase:auth");
Sam
  • 1,652
  • 17
  • 25