FireBaseUI Auth - how to know if account is from a new signup or existing user?

后端 未结 2 2132
野趣味
野趣味 2020-12-17 06:24

I am using firebaseUI for authentication. it essentially opens a a external activity and logs the user into firebase and sends the developer a call back in onActivityResult.

相关标签:
2条回答
  • 2020-12-17 06:54
    public boolean isNewSignUp(){
            FirebaseUserMetadata metadata = mAuth.getCurrentUser().getMetadata();
            return metadata.getCreationTimestamp() == metadata.getLastSignInTimestamp();
        }
    

    At the time of writing, Looks like each logged in user has meta data as i suspected. we can check the last sign time to know if its a new account. I heard they will be making this easier in the future, check later versions of firebase authentication before attempting this.

    0 讨论(0)
  • 2020-12-17 06:55

    Do not use the creation and sign in timestamp comparison. I found it to be unreliable.

    IdpResponse has a isNewUser() method to tell you whether the login is a new account or not.

    0 讨论(0)
提交回复
热议问题