0

I'm working on incorporating Firebase Authentication into my Xamarin app. The Firebase docs say that indicate that I can access a new user's UID in a completion method after they complete the CreateUser() method (https://firebase.google.com/docs/auth/ios/start). I have the following code in my IOS project within my Xamarin solution:

Auth.DefaultInstance.CreateUser(email, password, (AuthDataResult authResult, Foundation.NSError error) => {

    authResult.User.GetIdToken((string token, Foundation.NSError error1) => 
    {
        Console.WriteLine("Token Is");
        Console.WriteLine(token);
    });

});

When the method fires, it says 'authResult' is Null. Specifically, the above method throws the following exception:

System.NullReferenceException has been thrown Object reference not set to an instance of an object.

How can I access the user's UID?

2
  • 1
    If there is an error creating the user, authResult.User will be null. Commented Nov 15, 2018 at 18:33
  • Sure enough, when I write the 'error' to the console, something comes up! Thanks! Commented Nov 15, 2018 at 18:55

1 Answer 1

1

If there is an error creating the user, authResult.User will be null. So you'll need to check for that in your code:

Auth.DefaultInstance.CreateUser(email, password, (AuthDataResult authResult, Foundation.NSError error) => {
  if (error == null) {
    authResult.User.GetIdToken((string token, Foundation.NSError error1) => {
        Console.WriteLine("Token Is");
        Console.WriteLine(token);
    });
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.