Can I stop Supabase from saving to local storage `...
# help
c
Can I stop Supabase from saving to local storage
supabase.auth.token
?
s
I don't think you can as this is how the library works
c
You actually can - the createClient() function has a third parameter - options - and one of its properties is persistSession
this is s flag indicating whether the token should be saved to local storage or not
of course, if you choose NOT to store it, the user will have to re-log-in on page refresh
s
oh wow learn something new everyday, thanks @User
c
How does this affect
onAuthStateChanged()
? I don't rely on the local storage but rather the built-in function
c
I don't think I understand your question - which built-in function are you referring to?
c
I use
onAuthStateChanged()
to verify if user is logged in or not
c
Short answer: turning off local storage should NOT have an effect on this method in most scenarios
Long answer: local storage and onAuthStateChanged() are two independent things (for the most part, see the note below): 1) Local storage only indicates whether the token you get from the server gets stored in local storage or not. The reason why you would want to store it there is to keep the user logged in even if they refresh the page or close and reopen the browser 2) Regardless of whether you store the token in local storage or NOT, this method will still inform you when different auth events happen (e.g. user signed in, signed out, etc). NOTE: I think the only possible issue might be that if you choose to NOT store the token in local storage and close the browser or refresh the page, you would NOT get the signed-out even, even though the user is practically signed out.
c
Very insightful. I think for now I will leave the local storage. I was unsure if this was a security risk