firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
201 stars 33 forks source link

[Bug] User ID change between firebase versions #896

Open murilobast opened 8 months ago

murilobast commented 8 months ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

I have updated Firebase to 11.4.0 months ago, everything worked fine until I tried running a standalone Windows build, had the good and old crash on start that is usually fixed by installing redistributables (check box on steamworks). Knowing that 10.3.0 worked before I rolled back to 10.3.0 and things started working again.

All good until I tried to build for iOS, everything works correctly but for some reason the userId I get from firebase auth is different from what I get with 11.4.0 or what I used to get with 10.3.0. No code has changed on my side, it was just a version change. And to confirm it was the version, if I build with 11.x.0 I get the correct userId, but with 10.x.0 I get a new one.

Example code below:

On 11.x.0 newUser.UserId is cuzPiRT7QFgPZ2COBC0hbMGlvGU2 On 10.x.0 newUser.UserId is Y7Bj2PKv3maCmrPIMdTGd1YluUC3

Steps to reproduce:

Upgrade to 11.x.0 Fetch the userId Downgrade to 10.x.0 Fetch the userId userId is now different on 10.x.0

Relevant Code:

using UnityEngine;
using UnityEngine.SocialPlatforms.GameCenter;

public class GameCenterLogin {
    public static void Initialize() {
        GameCenterPlatform.ShowDefaultAchievementCompletionBanner(true);

        Social.localUser.Authenticate((bool success) => {
            if (success) SignInWithGameCenterAsync();
            else CloudLogin.OnFail();
        });
    }

    private static void SignInWithGameCenterAsync() {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        var credentialTask = Firebase.Auth.GameCenterAuthProvider.GetCredentialAsync();

        credentialTask.ContinueWith(cTask => {
            if (!cTask.IsCompleted || cTask.Exception != null || cTask.IsCanceled || cTask.IsFaulted) {
                Debug.Log("GCL credentialTask failed"  + cTask.Exception.Message);
                CloudLogin.OnFail();
                return null;
            }

            var credential = cTask.Result;

            auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                if (task.IsCanceled || task.IsFaulted) {
                    CloudLogin.OnFail();
                    Debug.Log("GCL SignInWithCredentialAsync failed");
                    return;
                }

                Firebase.Auth.FirebaseUser newUser = task.Result;

                CloudLogin.OnSuccess(newUser.DisplayName, newUser.UserId);
            });

            return credential;
        });
    }

    public static void OpenRankingUI() {
        Social.ShowLeaderboardUI();
    }
}
paulinon commented 7 months ago

Hi @murilobast,

I haven't been able to reproduce this behavior so far. Could you provide the complete steps you've taken when you encountered the issue? You may provide a minimal, reproducible example as this could be used as a baseline for troubleshooting.

murilobast commented 7 months ago

@paulinon it started happening after the latest iOS update.

It's simple, if I build with Firebase 10.3.0, for example, FirebaseUser.UserId is X. Then if I install Firebase 11.4.0, with the same codebase but changing FirebaseUser.UserId to AuthResult.User.UserId, since the API is different now, I get Y as the userId.

The reinstall is a complete reinstall, completely removing all Firebase files, including the ones outside of the Firebase folder.

Issue is reproducible with an empty project, using the code snippet in the OP. I'm publishing a new beta version to testflight with 11.4.0 (the prior version was 10.3.0), and already got users having different userId than what they had on an older version. User id is user accessible and used to link game progress to the discord server.

deveshbeniwal commented 6 months ago

I am facing the same code, I am using the almost same code but yes user id has been changed when old users come again! Do anyone have any idea how to solve that would be helpful. Thanks

argzdev commented 1 week ago

Hey folks, I was able to reproduce this behavior. I'll notify our engineers regarding this finding. Thanks!