How do i tell if the session/user in local storage is the most current one? Im only using magic link for now. for example someone is uses multiple browsers at different times. Whats the best practice for that? Any help would be appreciated. i realize this is basic stuff, but its a first for me.
02/12/2022, 11:27 PM
Not that basic with jwt's. Normally Supabase does not restrict number of browsers, and there is not easy way to cancel jwt before it expires (although you can set time). Some have looked to device ids and a table for last login and RLS "magic".
Thanks, Im wondering if there is a property in the user object in local storage that we can compare with the user returned by getUser? Also what happens then when a localsession has expired or does it even expire? I mean the jwt token has an expiration, but doesn't the server take care of that?
02/13/2022, 12:25 AM
getUser needs a jwt, where are you getting that from? If you mean user() that just uses localstorage basically. The object in local storage is the session info (jwt, expire times, and the user object. Things work different on client only or SSR type situations.
02/13/2022, 12:35 AM
i think i might be making an issue that i don't have. but what i'm getting at is how do i tell if the user object in local storage matches the user object from getUser, or do i even need to?
02/13/2022, 12:48 AM
I have a basic client app using supabase.js. I've never needed getUser. Either there is a current user with user() or there is not, and I goto signIn logic. A bit more complicated than that. Supabase.js keeps the storage object current as long as it can refresh the token. You can use onAuthStateChange() to watch details (I use that function to detect signout). If you have server side code things are more complicated.
02/13/2022, 12:51 AM
Ah ha, thats exactly what i needed to know. thank you so much for your help.