My app is available for use with or without an account (as a guest).
When the app launches, I want to determine whether the user is a regular user or an anonymous user; if the user is a regular user, I want to determine whether the user is signed in or signed out; if signed in, show the homepage; otherwise, show the login page.
If the user is an anonymous user, then directly show HomePage.
If the user has not created an account anonymously, then allow them to create one.
When I use signInAnonymously()
it’s creating a new anonymous account each time.
Summary
show loginpage => if the user has not created an account both ways || regular user is not signin.
show Homepage => regular user is sigin || anonymous account is created.
Can anyone help me achieve this?
3
Answers
You have to activate the sign in with email in firebase so that your user can login in both ways. In your system , maybe you could do some checking when user launch the app for example you can check if their email exists by calling firebase authentication.
You can determine whether a user is anonymous by checking the
isAnonymous
property of their profile.I typically also add a check on whether the user has any
providerData
, as theisAnonymous
flag may show asfalse
when the user has linked-then-unlinked a provider.You’re not supposed to call signInAnonymously on every launch. You’re supposed to use an auth state observer first to find out if a user is signed in (anonymous or not), then using the result of that (now knowing if there is any user signed in or not), decide how to proceed. If you find there is a user already signed in, you can then check the User object property
isAnonymous
to see if they are anonymous or not.See: