the `isNew` boolean inside `SessionStatus` class, ...
# supabase-kt
r
the
isNew
boolean inside
SessionStatus
class, is this a 100% guarantee the user is really new? meaning the supabase user database has no record for this user? Meaning if i sign in from a different platform (eg ios) and then sign in with same account on android the isNew will return false? Even when the session on that device is 'new' (no local storage)
/**
* Whether the session is new, i.e. [source] is [SessionSource.SignIn], [SessionSource.SignUp] or [SessionSource.External].
* Use this to determine whether this status is the result of a new sign in or sign up or just a session refresh.
*/
val isNew: Boolean = source is SessionSource.SignIn || source is SessionSource.SignUp || source is SessionSource.External
this is what the docs, i want to rely user purchase actions on this boolean, so its important its always correct 🙂
or how else would you verify if the current user has no previous record
j
so not sure if I understand, what do you mean by no previous record?
r
example user A signs in on android device for first time. Purchases a digital item which gets stored in a supabase table user A signs in 1 month later on ios device (with same Gmail account). my app should then recognise this user already exists, and fetch the digital item from the supabase table based on userId. eg after signing in your class
SessionStatus
should provide me with info whether or not this user has signed in before
j
Yea so
SessionStatus
does not know if there is data in other tables for your user, you'd have to implement that logic yourself. What
isNew
checks, is whether the user just logged in, so there was no previous session before on this device (e.g. this would not be the case if the session was refreshed, so its not new)
r
what would be a good approach inside the
supabaseClient.auth.sessionStatus
stateflow to check if an authenticated user is 'new' in the definition I just gave?
i could look in the
appMetaData
or
userMetadata
JsonObjects
with Firebase SDK you have a boolean that tell you just what I need, to know if this user has signed in ever before, on any platform
looking for same thing on your SDK
j
i could look in the
appMetaData
or
userMetadata
JsonObjects
Either store a boolean in there on sign up, or maybe checking if
supabaseClient.auth.currentUserOrNull()?.lastSignInAt
is null (so there was no previous sign in?) but I'd check that with a new account
I don't know how FB does it but I think its safer to use the metadata or a separate table.
r
lastSignInAt
seems a good fit, im gonna test it with new account, thnx
for brand new user
lastSignInAt
is still not null, and its also not the same value as
createdAt
, both are an
Instant
and around 50ms apart. So basing logic on that but its not best option