firebase-unity-sdk icon indicating copy to clipboard operation
firebase-unity-sdk copied to clipboard

[Bug] User ID change between firebase versions

Open murilobast opened this issue 1 year ago • 7 comments

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2021.3.19f1
  • Firebase Unity SDK version: 10.3.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Auth (Auth, Database, etc.)
  • Other Firebase Components in use: Firestore, Analytics, CloudFunctions, Crashlytics
  • Additional SDKs you are using: Facebook, AdMob
  • Platform you are using the Unity editor on: Mac
  • Platform you are targeting: iOS
  • Scripting Runtime: IL2CPP
  • Pre-built SDK from the website or open-source from this repo: prebuilt

[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();
	}
}

murilobast avatar Nov 09 '23 00:11 murilobast

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.

paulinon avatar Nov 13 '23 18:11 paulinon

@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.

murilobast avatar Nov 14 '23 19:11 murilobast

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

deveshbeniwal avatar Jan 09 '24 09:01 deveshbeniwal

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

argzdev avatar Jun 25 '24 10:06 argzdev