简体   繁体   中英

How to check if the user is new registered user

I'm working on android application which works as expected , but I'm using FirebaseUI to authenticate users login , I'm using this code for authentication and registration :

startActivityForResult(AuthUI.getInstance()
                                    .createSignInIntentBuilder()
                                    .setIsSmartLockEnabled(false)
                                    .setAvailableProviders(Arrays.asList(
                                            new AuthUI.IdpConfig.EmailBuilder().build(),
                                            new AuthUI.IdpConfig.GoogleBuilder().build(),
                                            new AuthUI.IdpConfig.FacebookBuilder().build()))
                                    .build(),
                            RC_SIGN_IN);

Is there any way to know if the current user is new user after login using onActivityResult()

You can use cloud functions like this:

exports.sendWelcomeEmail = functions.auth.user().onCreate((event) => {
   // ...
 });

this function will trigger everytime a new user is created.

It will trigger when the following occurs:

  1. A user creates an email account and password.
  2. A user signs in for the first time using a federated identity provider.
  3. The developer creates an account using the Firebase Admin SDK.
  4. A user signs in to a new anonymous auth session for the first time.

more info here:

https://firebase.google.com/docs/functions/auth-events

It is explained in the repo: https://github.com/firebase/FirebaseUI-Android/tree/master/auth#user-metadata

The easiest way is to compare last sign in time to the creation time on the user to determine if the user is new or existing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM