gpt4 book ai didi

c# - 我使用 Firebase 的统一登录不起作用

转载 作者:行者123 更新时间:2023-12-05 05:04:22 25 4
gpt4 key购买 nike

我的注册用户工作正常,但是当我尝试登录用户时,我没有收到任何类型的消息,登录成功或登录失败。我正在尝试让我的用户登录,然后转到我的登录屏幕。如果有人能够看到我做错了什么,我将非常感激!我将在下面提供我的代码。感谢您的帮助!

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Text.RegularExpressions;
using UnityEngine.SceneManagement;
using Firebase;
using Firebase.Auth;

public class Login : MonoBehaviour {
public GameObject email;
public GameObject password;
private string Email;
private string Password;
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
void Update () {
if (email.GetComponent<InputField>().isFocused){
password.GetComponent<InputField>().Select();
}
if (Password != ""&&Password != ""){
LoginButton();
}
Email = email.GetComponent<InputField>().text;
Password = password.GetComponent<InputField>().text;
}

public void LoginButton()
{
auth.SignInWithEmailAndPasswordAsync(Email, Password).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
return;
}

if (task.IsFaulted) {
Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
return;
}

Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
SceneManager.LoadScene("LoginScreen");

});
}
}

最佳答案

ContinueWith替换为ContinueWithOnMainThread,我觉得你应该不错。如果没有,请确保您已在 Firebase 控制台中启用电子邮件登录。

我怀疑一切都按预期工作,但因为您正在使用 ContinueWith,所以您的 SceneManager 逻辑发生在主线程之外。在最好的情况下,这是行不通的。在最坏的情况下,您可能会看到崩溃。

查看我的 article on threading在 Unity 和 my video on Authentication获取更多信息。

关于c# - 我使用 Firebase 的统一登录不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61122991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com