firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

Can I login again with Same Anonymous Account #1320

Closed atif-infinityup closed 1 year ago

atif-infinityup commented 1 year ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

I have two Login Options. 1: Login with Google 2: Login as Guest

I am following this https://firebase.google.com/docs/auth/unity/anonymous-auth for login as anonymously. On login success It creates a unique user ID (That's a correct behaviour). But when I Logout using auth.SignOut(); (firebase Auth method).

and then for a reason I want to login as guest again It creates new user ID all the way. Is there anyway to get my old Authenticated data (with old USERID). Because based on this user ID I am saving some data in firebase database. Assigning new userid always is not good for my game requirements.

Login with Google (use firebase) is good. It always return FirebaseUser with same USERID.

google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

jonsimantov commented 1 year ago

Hi,

If you call SignInAnonymously without signing out, it will give you the same anonymous credentials as the last time, as the auth token is cached locally on the device.

If you sign out, the device will delete its locally cached credentials, so there is no way for it to get back the anonymous login. That's why you get a brand new anonymous login the next time you sign in.

I would suggest not calling auth.SignOut() when the app exits; this will leave the auth session active, even if the user is offline next time.

Note: If you are creating an anonymous account to help users store data before logging in, you may want to consider prompting them to link an auth provider (like email, Google signin, etc). This will ensure that even if they signs out, they won't lose the database items associated with their login.