【问题标题】:Using Firebase Auth to store additional information使用 Firebase Auth 存储附加信息
【发布时间】:2020-01-04 22:51:22
【问题描述】:

有谁知道这是否可能以及如何使用 firebase 身份验证来提供其他信息,例如用户名?

我创建了这个方法,但它只存储电子邮件和密码。

    public void create()
    {
        FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(emailInput.text, passwordInput.text).ContinueWith((task => {
            if (task.IsCanceled)
            {
                Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException;
                GetErrorMessage((AuthError)e.ErrorCode);
                return;
            }
            if (task.IsFaulted)
            {
                Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException;
                GetErrorMessage((AuthError)e.ErrorCode);
                return;
            }
            if (task.IsCompleted)
            {
                print("Created user");
                return;

            }
        }));


    }

我是 Unity 新手,我开始使用 Firebase 大约一周。 抱歉,如果我问了一些显而易见的问题,但我搜索了几天,但文档很少。

谢谢

【问题讨论】:

    标签: c# firebase unity3d firebase-authentication


    【解决方案1】:

    使用FirebaseUser.UpdateUserProfileAsync

    public void SetPlayerNameAndImage(string playerName, string imageUrl)
    {
        Firebase.Auth.FirebaseUser user = Firebase.Auth.FirebaseAuth.DefaultInstance.CurrentUser;
        if (user != null)
        {
            Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile
            {
                DisplayName = playerName,
                PhotoUrl = new System.Uri(imageUrl),
            };
            user.UpdateUserProfileAsync(profile).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("UpdateUserProfileAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("UpdateUserProfileAsync encountered an error: " + task.Exception);
                    return;
                }
    
                Debug.Log("User profile updated successfully.");
            });
        }
    }
    

    【讨论】:

      【解决方案2】:

      Firebase 身份验证只能将每个用户存储在 user profilecustom claims 的专用字段中。自定义声明的数据块限制为 1000 字节的 JSON,并且只能使用后端 SDK 而不是 Unity 客户端 SDK 编写。虽然您当然可以在自定义声明中存储有关用户的数据,但这并不是它的用途(它旨在使用后端安全机制授予访问权限)。

      您应该改为使用数据库(例如 Realtime DatabaseFirestore您希望他们访问的数据。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-08-17
        • 1970-01-01
        • 2017-04-21
        • 2015-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多