Search code examples
androidfirebasefirebase-authenticationfirebaseui

Check if the user has signed in for the first time or not, using Firebase AuthUI


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?


Solution

  • 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.