0

I'm trying to find out if the user who logs in using Google Sign-In does this the first time. I am using this Package.

I already tried to implement this code snippet from this question, however this solution is for Android and I need it for Xamarin.Droid. The problem is that the OnComplete function returns an Android.Gms.Tasks.Task, but I need IAuthResult to read the AddtionaleInformation.

Currently my code looks like this:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IOnSuccessListener, IOnFailureListener, IOnCompleteListener
 private void LoginWithFirebase(GoogleSignInAccount account)
        {
            var credentials = GoogleAuthProvider.GetCredential(account.IdToken, null);
            _firebaseAuth.SignInWithCredential(credentials).AddOnSuccessListener(this).AddOnFailureListener(this).AddOnCompleteListener(this, this);
        }


        public void OnComplete(Task<IAuthResult> task)
        {
            
        }

An my Error is the following

CS0535: 'MainActivity' does not implement interface member 'IOnCompleteListener.OnComplete(Task)'

I know that I didn't implement this function exactly as prescribed, but with the default method I can't retrieve Additional information

Does anyone have a solution or an approach?

wihaHeuer
  • 3
  • 2

1 Answers1

0

From Firebase doc, you can check the last sign-in timestamp against the created-at timestamp

 public void OnComplete(Task task)
    {
        if (task.IsSuccessful)
        {
           
            FirebaseUser user = auth.CurrentUser;
            IFirebaseUserMetadata metadata = auth.CurrentUser.Metadata;
            if (metadata.CreationTimestamp == metadata.LastSignInTimestamp)
            {
                // The user is new, show them a fancy intro screen!
            }
            else
            {
                // This is an existing user, show them a welcome back screen.
            }
        }
        else
        {
            Toast.MakeText(this, "Authentication failed.", ToastLength.Short).Show();
        }
    }
Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16