Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

SignInWithCustomToken method in Xamarin.Firebase.iOS.Auth give System.InvalidCastException. #213

Closed
matgallacher opened this issue Dec 6, 2018 · 3 comments · Fixed by #218
Assignees
Labels
azdo-sync Azure DevOps Sync
Projects

Comments

@matgallacher
Copy link

matgallacher commented Dec 6, 2018

Re-raising this from #187.

The code below is still valid

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            Firebase.Core.App.Configure();

            var token = "{mytokenreturnedfromapiby-await FirebaseAuth.DefaultInstance.CreateCustomTokenAsync(uid)}";

            Auth.DefaultInstance.SignInWithCustomToken(token, async (User user, NSError error) =>
            {
            });

            return base.FinishedLaunching(app, options);
}

VS bug #742856

@igdit
Copy link

igdit commented Dec 6, 2018

Having the same issue. It is definitely related to the AuthResultHandler, since passing in null works fine. In the meantime, I'm having to settle for an ugly workaround that "times out" if the auth state never changes after a set amount of time (could also leverage AddAuthStateDidChangeListener):

        Auth.DefaultInstance.SignInWithCustomToken(token, null);

        // attempt for 5 seconds before giving up
        var attempts = 50;
        while(Auth.DefaultInstance.CurrentUser == null && attempts > 0)
        {
            await Task.Delay(100);
            attempts--;
        }
        return Auth.DefaultInstance.CurrentUser;

@bazookajoey
Copy link

I can +1 this issue for me on the Auth 5.0.4 package. SignInWithCustomTokenAsync and SignInWithCustomToken both throws this exception.

My app listens for auth state changes, I validated that the state change handler is fired before crashing.
Auth.DefaultInstance.AddAuthStateDidChangeListener((auth, user) => StateDidChange(user, handler));

@Redth Redth added this to High priority in Triage Dec 6, 2018
@Redth Redth added the azdo-sync Azure DevOps Sync label Dec 6, 2018
@SotoiGhost SotoiGhost self-assigned this Dec 6, 2018
@SotoiGhost
Copy link
Contributor

Thanks for the information guys! As there is a workaround now, I'll look a this, not now, but very soon. This was marked as a high priority for us.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azdo-sync Azure DevOps Sync
Projects
Triage
  
Closed
Development

Successfully merging a pull request may close this issue.

5 participants