Firebase LinkWithCredentialAsync并非实际触发验证状态监听器

时间:2018-01-30 16:58:02

标签: c# firebase xamarin xamarin.android firebase-authentication

在注册我的Xamarin Android应用程序时,我是匿名签名用户才能访问数据库。验证所有输入后,我使用LinkWithCredentialAsync创建/组合实际用户帐户和匿名用户帐户。出于某种原因,Firebase在通话结束后没有通知我的听众,即使日志表明它是。为什么Firebase实际上没有通知听众发生了更改?

日志:

01-30 10:27:41.221 D/AuthState( 5631): Signing in anonymously.
01-30 10:27:41.450 D/AuthStateListener( 5631): Auth state was changed.
01-30 10:27:41.451 D/Mono    ( 5631): Assembly Ref addref Xamarin.Firebase.Database[0x7f8bffefb900] -> Xamarin.GooglePlayServices.Tasks[0x7f8bffefc000]: 4
01-30 10:27:41.457 D/AuthState( 5631): AuthCallback function called.
01-30 10:27:43.989 D/FirebaseAuth( 5631): Notifying id token listeners about user ( 8zM08FI8PNRcWW7Zdt7QGQvkM173 ).
01-30 10:27:43.989 D/FirebaseAuth( 5631): Notifying auth state listeners about user ( 8zM08FI8PNRcWW7Zdt7QGQvkM173 ).
01-30 10:27:43.989 D/FirebaseApp( 5631): Notifying auth state listeners.
01-30 10:27:43.989 D/FirebaseApp( 5631): Notified 1 auth state listeners.
01-30 10:27:43.989 D/AuthStateListener( 5631): Auth state was changed.
01-30 10:27:43.991 D/AuthState( 5631): AuthCallback function called.
01-30 10:27:43.996 D/Mono    ( 5631): DllImport searching in: '__Internal' ('(null)').
01-30 10:27:43.996 D/Mono    ( 5631): Searching for 'java_interop_jnienv_call_boolean_method'.
01-30 10:27:43.996 D/Mono    ( 5631): Probing 'java_interop_jnienv_call_boolean_method'.
01-30 10:27:43.996 D/Mono    ( 5631): Found as 'java_interop_jnienv_call_boolean_method'.
01-30 10:27:45.316 D/Mono    ( 5631): Assembly Ref addref Xamarin.Firebase.Common[0x7f8bffefb700] -> Xamarin.GooglePlayServices.Basement[0x7f8bffefbf00]: 2
01-30 10:27:45.321 D/AuthState( 5631): Linking anonymous account with credentials.
01-30 10:27:46.344 D/FirebaseAuth( 5631): Notifying id token listeners about user ( 8zM08FI8PNRcWW7Zdt7QGQvkM173 ).
01-30 10:27:46.346 D/FirebaseApp( 5631): Notifying auth state listeners.
01-30 10:27:46.346 D/FirebaseApp( 5631): Notified 1 auth state listeners.

以下代码已经减少,但应该很好地了解我如何使用它。

AuthStateListener:

public class AuthStateListener : Java.Lang.Object, FirebaseAuth.IAuthStateListener
    {
        Action<FirebaseUser> Callback;

        public AuthStateListener(Action<FirebaseUser> oAction)
        {
            this.Callback = oAction;
        }

        public void OnAuthStateChanged(FirebaseAuth auth)
        {
            Log.Debug("AuthStateListener", "Auth state was changed.");
            Callback.Invoke(auth.CurrentUser);
        }
    }

AuthStateListener Init:

AuthStateListener oListener = new AuthStateListener(AuthCallback);
oAuth.AddAuthStateListener(oListener);

if (FirebaseAuth.Instance.CurrentUser == null)
{
    SignInAnon();
}

SignInAnon:

public async void SignInAnon()
        {
            try
            {
                Log.Debug("AuthState", "Signing in anonymously.");
                await oAuth.SignInAnonymouslyAsync();
            }
            catch
            {
                oDialogHelper.ShowDialog("There was an error. Please try again.");
            }

        }

LinkWithCreds:

public void LinkWithAnonymous()
        {
            try
            {
                AuthCredential oCred = EmailAuthProvider.GetCredential(txtEmail.Text, txtPasswordConfirm.Text);
                Log.Debug("AuthState", "Linking anonymous account with credentials.");
                oAuth.CurrentUser.LinkWithCredentialAsync(oCred);
            }
            catch (Exception ex)
            {
                //Something went wrong (email already used, username in use, etc...)

            }
        }

AuthCallback:

public void AuthCallback(FirebaseUser oUser)
        {
            Log.Debug("AuthState", "AuthCallback function called.");
            //do something
        }

1 个答案:

答案 0 :(得分:0)

我认为Xamarin.Firebase.Auth包中存在问题/变化。我注意到在更新NuGet包之后代码停止了工作。

在不更改任何代码的情况下,我又回到了版本42.1021.1,并且eveything按预期工作。我建议任何遇到身份验证问题的人都会降级到以前的版本。

我已经在Xamarin Components GitHub上开始了一个新问题,可以在这里找到:https://github.com/xamarin/XamarinComponents/issues/294