I know that in the basic firebase authentication I can use AdditionalUserInfo.isNewUser()
method in the OnCompleteListener.onComplete
callback to see if the user is new or not. But, how do I get it done using the new pre-built FirebaseUI for authentication?

- 565,676
- 79
- 828
- 807

- 421
- 2
- 7
- 22
2 Answers
In my last try to get the result of isNewUser()
with Firebase simple UI. I did print all of Intent data
in protected void onActivityResult(int requestCode, int resultCode, Intent data)
by this answer in which we can realise that data
contains a IdpResponse ParcelableExtra that have isNewUser()
value.
IdpResponse idpResponse = data.getParcelableExtra("extra_idp_response");
Log.e("TAG", "isNewUser= " + idpResponse.isNewUser());

- 3,142
- 5
- 26
- 50
Since FirebaseUI is simply a UI built on top of Firebase, the two can be used together without problems. But unfortunately the AdditionalInfo
can only begotten from an AuthResult
, which is only available when the user actively signs in, e.g. signInWithEmailAndPassword
. It looks like there is no way to get it from an AuthStateListener
As @bojeil said in the comments, a less reliable way that may work is to check the value of metadata.getCreationTimestamp()
and metadata.getLastSignInTimestamp
. If those are the same, the user was just created. For an example of this, see the FirebaseUI documentation.

- 565,676
- 79
- 828
- 807
-
Can you share an example code? That would be really helpful – Umair Javaid Jul 29 '18 at 23:51
-
Hmmm.... as far as I can see you can only get the `AdditionalInfo` from an `AuthResult`, which is only available when the user actively signs in, e.g. `signInWithEmailAndPassword`: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth.html#signInWithEmailAndPassword(java.lang.String,%20java.lang.String). So it looks like there is no way to get it from an `AuthStateListener`. – Frank van Puffelen Jul 30 '18 at 00:22
-
1One less reliable way of doing this is checking https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#getMetadata(). It gives you access to the user creation and sign in time. You could use that to compute if the user is new or existing. – bojeil Jul 30 '18 at 07:20
-
1Here is the link in FirebaseUI: https://github.com/firebase/FirebaseUI-Android/tree/master/auth#user-metadata – bojeil Jul 30 '18 at 07:24
-
1@FrankvanPuffelen Those 2 values were returning timestamps 2 milliseconds apart for Google sign-in on my device. It's not reliable. – Anthony Chuinard Jun 05 '19 at 05:52