Hey folks! Quick question. Is it possible to use ...
# android
s
Hey folks! Quick question. Is it possible to use Firebase Phone Auth to JUST verify OTP but use Email Sign in to create and sign in a user?
So basically I would want to verify the OTP, validate the credentials object but then create a user using email and password. Possible?
d
Please check the channel topic
n
Think you would need to use a phone number verification provider. Firebase Phone Auth is just for authentication.
I take back my comment, you can actually do it. To verify or send an OTP to user you do the following 👇🏾
Copy code
val options = PhoneAuthOptions.newBuilder(auth)
 .setPhoneNumber(phoneNumber)
 .setTimeout(60L,TimeUnit.SECONDS)
.setActivity(this)
.setCallbacks(callbacks)
.build()
PhoneAuthProvider.verifyPhoneNumber(options)
If you notice, there's a setCallbacks option... You can use that option to check if the number is verified and proceed with the authentication but in your case, you can just switch to the email authentication in callback since you were only interested in verifying the phone number.
s
Thanks for the reply. But I wouldn't be able to use email verification callback for a Phone Auth right?
Yeah I am using the default verification callbacks provided by the Phone Auth. Once the code is sent, I can create a credentials object with the verification ID and the otp. But using that, is there a way to verify the OTP entered with Firebase WITHOUT creating a user?
The only work around I see to this at the moment is to call
signInWithPhoneAuthCredential(credential)
and once the user is created, I can create another user with email and password and then link these two accounts. My only concern is that this might shoot up the auth creation limits once we scale? Is this a wise option though?
n
I'm not sure you can prevent firebase from creating a new user when the phone number is verified. Auth linking would be the only viable option.
I would suggest you just use a third-party phone number verification like Nexmo or any SMS sending platform and implement the OTP sending and verification.
s
Thanks for the help @Nuru 🙂 Really appreciate it
z
This is not kotlin related