如何在C#中添加Firebase身份验证状态列表器

时间:2019-07-25 09:59:56

标签: c# android firebase xamarin firebase-authentication

我需要在visual-studio-2019中具有身份验证状态侦听器,以在用户身份验证状态更改时通知我。我是一个初学者程序员,不知道如何。卡住一段时间会很有帮助。 尝试过此方法,因为可能无法解决  Firebase.Auth.FirebaseAuth身份验证;         Firebase.Auth.FirebaseUser用户;

    // Handle initialization of the necessary firebase modules:
    void InitializeFirebase()
    {
        Debug.Log("Setting up Firebase Auth");
        auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        auth.StateChanged += AuthStateChanged;
        AuthStateChanged(this, null);
    }

    // Track state changes of the auth object.
    void AuthStateChanged(object sender, System.EventArgs eventArgs)
    {
        if (auth.CurrentUser != user)
        {
            bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null;
            if (!signedIn && user != null)
            {
                Debug.Log("Signed out " + user.UserId);
            }
            user = auth.CurrentUser;
            if (signedIn)
            {
                Debug.Log("Signed in " + user.UserId);
            }
        }
    }

    void OnDestroy()
    {
        auth.StateChanged -= AuthStateChanged;
        auth = null;
    }

它给了一些错误,如图errors recieved

所示

0 个答案:

没有答案