Home > other >  Can createUserWithEmailAndPassword called be multiple times?
Can createUserWithEmailAndPassword called be multiple times?

Time:12-10

I'm asking this because I want display a message to the user only once:

auth.createUserWithEmailAndPassword(email, password)
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                val isUserNew = authResult.additionalUserInfo!!.isNewUser!!
                if(isUserNew) {
                    Toast.makeText(baseContext, "Hello", Toast.LENGTH_SHORT).show()
                }
            } else {
                Log.d(TAG, task.exception!!.message!!)
            }
        }

So can isUserNew be false? Or it's always true since createUserWithEmailAndPassword is only called once? And I don't even need to check that.

CodePudding user response:

AdditionalUserInfo is also used in other auth methods so, isUserNew is there for convenience.

If user deleted the app and signed in again, or logged in via Google on second device for example, isUserNew will be false. But in this particular case it will always be true.

  • Related