简体   繁体   English

Firebase LinkWithCredentialAsync实际上未触发身份验证状态侦听器

[英]Firebase LinkWithCredentialAsync Not Actually Firing Auth State Listener

In the registration of my Xamarin Android app, I sign the user in anonymously in order to hit the database. 在Xamarin Android应用程序的注册中,我以匿名方式登录用户以访问数据库。 After all of the inputs are validated, I use LinkWithCredentialAsync to create / combine the actual user account with the anonymous one. 验证所有输入后,我使用LinkWithCredentialAsync来创建/将实际用户帐户与匿名帐户合并。 For some reason Firebase is not notifying my listener after the call is complete, even though the logs suggest that it is. 由于某种原因,Firebase不会在呼叫完成后通知我的侦听器,即使日志显示确实如此。 Why isn't Firebase actually notifying the listener that a change has occurred? Firebase为什么不真正通知侦听器已发生更改?

LOGS: 日志:

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.

The following code has been reduced, but should give a good idea of how I use it. 以下代码已减少,但是应该很好地说明我的用法。

AuthStateListener: 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初始化:

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: 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: AuthCallback:

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

I think there is an issue / change in the Xamarin.Firebase.Auth package. 我认为Xamarin.Firebase.Auth包中存在问题/更改。 I noticed the code stopped working after I updated the NuGet package. 我注意到更新NuGet软件包后代码停止工作。

Without changing any code, I reverted back to version 42.1021.1 and eveything works as expected. 在不更改任何代码的情况下,我恢复了版本42.1021.1,并且迁移功能按预期工作。 I suggest that anyone who runs into issues with authentication downgrade to the previous version. 我建议任何遇到身份验证问题的人都应降级到以前的版本。

I have started a new issue on the Xamarin Components GitHub that can be found here: https://github.com/xamarin/XamarinComponents/issues/294 我已经在Xamarin组件GitHub上开始了新的发布,可以在这里找到: https : //github.com/xamarin/XamarinComponents/issues/294

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM