Unity项目中的Firebase auth.SignOut()

时间:2017-04-28 18:37:20

标签: c# authentication firebase unity3d backend

我一直有这个问题。每当我让用户注销并尝试再次连接时,应用程序就会冻结并崩溃。知道会发生什么吗?

Ps。:起初我认为原因是有多个脚本处理firebase行为(我重新启动了SplashScreen场景,其中游戏对象使用“DontDestroyOnLoad()”统一方法实例化)。所以我最终得到了一些重复的脚本,我认为这可能导致崩溃,但我已经解决了这个问题并且崩溃继续。

编辑:这是我用来登录用户的代码

public void SignInWithCredentials(string email, string password) {
    if (auth.CurrentUser == null && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password)) {
        Credential credential = EmailAuthProvider.GetCredential(email, password);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled) {
                Debug.Log("------------------------- User sign in canceled.");
            } else if (task.IsFaulted) {
                Debug.Log("------------------------- User sign in encountered an error.");

                ButtonManager.Instance.panelLoginInfo.GetComponent<UIControllerExample>().Play();

                foreach (var e in task.Exception.InnerExceptions) {
                    FirebaseException firebaseException = (FirebaseException)e;
                    Debug.Log("------------------------- " + firebaseException.Message);
                }
            } else if (task.IsCompleted) {
                Debug.Log("------------------------- User sign in completed.");
                if (auth.CurrentUser != null) {
                    Debug.Log("------------------------- User info: " + auth.CurrentUser.Email + "    " + auth.CurrentUser.ProviderId);
                }

                if (!auth.CurrentUser.IsEmailVerified) {
                    Debug.Log("------------------------- User not comfirmed your email. Send new verification.");
                    auth.CurrentUser.SendEmailVerificationAsync().ContinueWith(taskVerification => {
                        if (taskVerification.IsCanceled) {
                            Debug.Log("------------------------- User verification email canceled send.");
                        } else if (taskVerification.IsFaulted) {
                            Debug.Log("------------------------- User verification email encountered an error.");
                            foreach (var e in task.Exception.InnerExceptions) {
                                FirebaseException firebaseException = (FirebaseException)e;
                                Debug.Log("------------------------- " + firebaseException.Message);
                            }
                        } else if (taskVerification.IsCompleted) {
                            Debug.Log("------------------------- User verification email send.");

                            SaveSession.Instance.SaveUserCredentials();
                            StartCoroutine(WaitToLoadScene("EmailCheck"));
                        }
                    });
                } else {
                    Debug.Log("------------------------- User confirmed your email.");

                    SaveSession.Instance.SaveUserCredentials();
                    StartCoroutine(WaitToLoadScene("City"));
                }

            } else {
                Debug.Log("------------------------- Something really really wrong happen.");
            }
        });
    } else if (auth.CurrentUser != null) {
        Debug.Log("------------------------- You have user logged in: " + auth.CurrentUser.Email);
    } else if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) {
        Debug.Log("------------------------- Complete all blanck spaces.");
    }
} 

这是我用来注销用户的代码:

public void LogOut () {
    auth.SignOut();
    user.DeleteAsync();

    if (FB.IsLoggedIn) {
        FacebookManager.Instance.isLogIn = "false";
        PlayerPrefs.SetString("Login", FacebookManager.Instance.isLogIn);
        PlayerPrefs.Save();
        FB.LogOut();
    }

    if (File.Exists(credentialsPath)) {
        File.Delete(credentialsPath);
    }

    StartCoroutine(WaitToLoadScene("SplashScreen"));
}

0 个答案:

没有答案