【问题标题】:Unity Firebase Authentication CreateUserWithEmailAndPasswordAsync returns empty UserIDUnity Firebase 身份验证 CreateUserWithEmailAndPasswordAsync 返回空 UserID
【发布时间】:2021-02-19 19:28:12
【问题描述】:

当我运行 CreateUserWithEmailAndPasswordAsync() 时,任务返回为 IsCompleted 并且 FirebaseUser 也不为空,但用户 ID 和电子邮件为空/空。我可以在 firebase 控制台中看到新用户(使用 UserID)。

尝试使用新创建的用户进行 SignInWithEmailAndPasswordAsync() 时也会发生同样的情况。但是,当我使用旧用户帐户 SignInWithEmailAndPasswordAsync() 时,一切正常。

这很奇怪,因为它与我一年前使用的代码相同。与此同时,我确实将 Firebase SDK 更新到了 7.0.2。这可能是问题的原因吗?

这是我创建新用户的代码:

public static async Task<CallbackMessage> RegisterNewUser(string email, string password)
        {
            CallbackMessage callback = new CallbackMessage();
            callback.isSuccess = false;

            if (!await DatabaseManager.CheckConnection())
            {
                callback.notConnected = true;
                return callback;
            }

            return await auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    callback.errorMessage = "Create User was canceled";
                }
                else if (task.IsFaulted)
                {
                    callback.errorMessage = GetErrorMessage(task.Exception);
                }
                else if (task.IsCompleted)
                {
                    FirebaseUser newUser = task.Result;
                    Debug.Log("User created succesfully! userID: " + newUser.UserId);
                    callback.userID = newUser.UserId;
                    callback.email = newUser.Email;
                    callback.isSuccess = true;
                }

                CleanTask(task);
                return callback;
            });
        }

真的可以在正确的方向上轻推一下 :)

【问题讨论】:

    标签: c# firebase unity3d firebase-authentication


    【解决方案1】:

    我能够解决它。对 Firebase Auth 服务的怀疑表示歉意。

    在我的 AuthStateChanged 代码中,每当用户登录但尚未通过电子邮件验证时,我都会添加一个 Signout()。这就是问题所在。

    我猜发生了什么:当调用用户创建时,它会立即让用户登录,然后去 Firebase 在那里进行设置。同时,我退出了用户,因为它没有通过电子邮件验证。当回调返回时,它会查找在转到 Firebase 之前登录的 FirebaseUser,但什么也没找到。

    就像在某人即将坐下时从下面拉椅子一样:P

    【讨论】:

      猜你喜欢
      • 2020-03-07
      • 2018-01-19
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      相关资源
      最近更新 更多