firebase / quickstart-unity

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

Firebase Auth: On Google logout, sign in back to Anonymous account? #1317

Closed JaineshPathak closed 1 year ago

JaineshPathak commented 1 year ago

[REQUIRED] Please fill in the following fields: Unity editor version: 2021.3.16f1 Firebase Unity SDK version: 8.2.0 Source you installed the SDK: .unitypackage Problematic Firebase Component: Auth Other Firebase Components in use: Database, Remote Config, Firestore Additional SDKs you are using: Facebook, Ironsrc Platform you are using the Unity editor on: Windows Platform you are targeting: Android Scripting Runtime: IL2CPP

[REQUIRED] Please describe the question here:

Hello.

I am using anonymous account sign in when a new user installs the app and in-game currencies are stored in that account using firestore. I have given user option to login with their Google account. This works fine.

My questions are:

  1. What happens to that anonymous account when the user decides to login/logout with his Google account?
  2. Also after Google logout, is it possible to sign in back to that anonymous account so that I can retrieve the in-game currencies stored in the anonymous account? If yes how?

Thank you.

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.

AlmostMatt commented 1 year ago

You might find these pages helpful: https://firebase.google.com/docs/auth/unity/account-linking https://firebase.google.com/docs/auth/unity/anonymous-auth

The recommended flow is that:

The expectation is that one firebase user can have multiple associated authentication methods. It should still be the same firebase account.

Let me know if you need any more information.

JaineshPathak commented 1 year ago

Thank you for replying. If I understood correctly, LinkWithCredentialAsync() will link google account and anonymous account together, so that means Current User ID won't change and will remain the same when given by anonymous account. Correct?

What if user uninstalls the app and later decides to reinstall. He will be signed in with a new fresh anonymous account and if he tries to link his same Google account, it will be linked with the recent newly anonymous account and not old ones right?

So he won't be able to get old in-game currencies back previously stored in google account and will be overwritten by in-game currency values stored in new anonymous account.

AlmostMatt commented 1 year ago

If I understood correctly, LinkWithCredentialAsync() will link google account and anonymous account together, so that means Current User ID won't change and will remain the same when given by anonymous account. Correct?

Yes, this is correct.

What if user uninstalls the app and later decides to reinstall. He will be signed in with a new fresh anonymous account and if he tries to link his same Google account, it will be linked with the recent newly anonymous account and not old ones right?

So he won't be able to get old in-game currencies back previously stored in google account and will be overwritten by in-game currency values stored in new anonymous account.

If the user previously linked a google account to their account, then in the future they should choose to sign in using the google account instead of trying to link it again.

I'm not sure exactly what would happen if the user tried to link the same google account to multiple different accounts, but I suspect that the second attempt to link would fail.

google-oss-bot commented 1 year ago

Hey @JaineshPathak. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@JaineshPathak if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.