firebase / firebase/firebase-unity-sdk

[Bug] User ID change between firebase versions

Open
#896 7 comments 0 reactions 0 assignees View on GitHub
api: auth type: bug type: question
Dominant language
C#
Stars
320
Forks
60
Avg merge
13h 32m
Merged PRs (30d)
13

Description

### [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](https://firebase.google.com/download/unity) 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:
```c#
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();
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the GameCenterLogin.Initialize and SignInWithGameCenterAsync entry points shown in the issue, then reproduce the iOS builds with Firebase Unity SDK 10.x and 11.x. Compare the Firebase Auth results from auth.SignInWithCredentialAsync and verify that the returned UserId remains consistent across the versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, firebase, ios, unity
Domain
authentication, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.