Android Firebase Phone Auth Not Receiving SMS Second Time - android

Hi I am trying to do a phone auth in android using firebase. The first time I install the app the sms comes and verification is successful but subsequently the sms does not come again. I have deleted the user from the auth in firebase and still it is not working.
Following is my code.
MainActivity.java
public class MainActivity extends AppCompatActivity {
CountryCodePicker ccp;
EditText editTextPhone, editTextCode;
FirebaseAuth mAuth;
String codeSent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
editTextCode = findViewById(R.id.editTextCode);
editTextPhone = findViewById(R.id.editTextPhone);
findViewById(R.id.buttonGetVerificationCode).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendVerificationCode();
}
});
findViewById(R.id.buttonSignIn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
verifySignInCode();
}
});
}
private void verifySignInCode() {
String code = editTextCode.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(codeSent, code);
signInWithPhoneAuthCredential(credential);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
//here you can open new activity
Toast.makeText(getApplicationContext(),
"Login Successfull", Toast.LENGTH_LONG).show();
} else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(getApplicationContext(),
"Incorrect Verification Code ", Toast.LENGTH_LONG).show();
}
}
}
});
}
private void sendVerificationCode() {
String phone = editTextPhone.getText().toString();
if (phone.isEmpty()) {
editTextPhone.setError("Phone number is required");
editTextPhone.requestFocus();
return;
}
if (phone.length() < 6 || phone.length() > 13) {
editTextPhone.setError("Please enter a valid phone");
editTextPhone.requestFocus();
return;
}
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phone, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
Toast.makeText(MainActivity.this,
"SMS Sent, Please Wait....", Toast.LENGTH_LONG).show();
editTextCode.requestFocus();
}
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
}
#Override
public void onVerificationFailed(FirebaseException e) {
}
#Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
codeSent = s;
}
};
}
EDIT
restarting the phone allows resending the sms after the 60 second timeout set in the function above. So it seems the phone is keeping something in the memory.

In my case, I have my number on
Phone numbers for testing (optional)
Removing it from there, firebase started sending SMS Code to my number. Spark Plan offer 10k phone auth per month. So that you can test and deploy your app without paying a penny.

In case someone is not getting the concept or reason of not sent sms again then please go through on my below details. I have been confused for very long time that why I didn't get sms for second time, third and so on..
First Read the original documentation:
onVerificationCompleted(PhoneAuthCredential)
This method is called in two situations:
Instant verification: in some cases the phone number can be instantly verified without needing to send or enter a verification
code.
Auto-retrieval: on some devices, Google Play services can automatically detect the incoming verification SMS and perform
verification without user action. (This capability might be
unavailable with some carriers.)
What I found:
onVerificationCompleted:
is only called when instant verification or auto-retrieval occurs.
When you try this for the first time you will get the otp code
from Google but the next time you try it, it can cause instant verification
to get active.
You can do:
So if you are debugging and having problem with not
receiving otp code from google just disable your sim card and enable it
again. This will help you in getting the otp codes from google again for
one more time until you enter your code and instant verification gets
activated again
Please note:
I don't think there is any way you can disable instant
verification as of now. But you can always optimize your code in a way it
doesn't create any problem for you and your users.
If you want to explore more then please check the thread: Click here

You must clear data for this app from phone. If not then run remove app and restart your phone will clear all data related with this app and re-run it.

In my case, I was found the next solution:
You need to update your Google Play Market to the latest version. You can do this in like this: Go to Play Market -> Click on "burger button" -> Select "Settings" in the menu -> Go to the bottom of the menu and you will find "Play Market Version" -> Click into it
Go to Phone Setting -> Go to Applications section -> Select Google Play Settings App -> Clear data\cahce -> then Select Google Play Market App -> Clear data\cahce
Reboot your device after the above steps.
Try again to send SMS to your device.
This solution will help you if you already tried to delete your user from the "White list" in the phone auth section, tried to delete phone number from a user database, and do other tries to fix this issue.

Related

I am not getting the verification code using Firebase phone authentication

I only want to get the OTP first. Then I will create an account. But I am unable to get OTP. The phone number format is also correct. Below is my code. Is there any error in it?
I think PhoneAuthProvider.getInstance().verifyPhone() is working properly so there will no error in it.
public class second extends AppCompatActivity {
EditText phoneNumberET, OTPET;
String phoneNumber, verificationCode;
FirebaseAuth mAuth;
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBack;
public void submit(View view)
{
phoneNumber = phoneNumberET.getText().toString();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
60,
TimeUnit.SECONDS,
TaskExecutors.MAIN_THREAD,
mCallBack
);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
phoneNumberET = (EditText) findViewById(R.id.phoneNumberEditText);
OTPET = (EditText) findViewById(R.id.OTPEditText);
mAuth = FirebaseAuth.getInstance();
mCallBack = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(#NonNull PhoneAuthCredential phoneAuthCredential) {
Log.i("complete","inside");
}
#Override
public void onCodeSent(#NonNull String s, #NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationCode = s;
}
#Override
public void onVerificationFailed(#NonNull FirebaseException e) {
}
};
}
}
As I know, there are some policies with Firebase Phone Authentication.
Example:
If you're trying to login with a same number several times, Firebase Authentication server will automatically block that number by thinking it as a spam number.
Try to login with several numbers in several times. (I know it's painful!)
If you're trying with just one number, you can wait for some time for your next login with that number.
There is a solution for debugging:
You can create some testing phone numbers and verification code for debugging your app with Firebase Phone Authentication. To do this:
Go to your Firebase Console
Go to Authentication
Click on Phone and you'll find Phone numbers for testing (optional)
Add your testing phone number with country code +1. And, also add your verification code for that number.
Click Add then, Save
In this way, you can easily test your app even in Emulator with Firebase Phone Authentication!
If you can not receive verification SMS with any device or any number, Please have a look at this answer to check correct implementation.
If you are facing issue sometimes, then you should try Test with whitelisted phone numbers.

How to check whether a user is email verified or not through a listener?

I have got an activity EmailSignUpActivity, it has two buttons, one to create a user and another one to verify the email. After a user is created, the Verify Email button would be pressed by the user which would send the verification email to the registered email.
What I am doing here is keeping the user to the EmailSignUpActivity till he verifies the email and then send him to the MainActivity. To achieve that I am using the following code:
// sending email verification
emailVerificationButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
progressDialog1.show();
if(mAuth.getCurrentUser() != null) {
if (emailEditText.length() != 0 && passwordEditText.length() != 0 && reEnterPasswordEditText.length() != 0) {
mAuth.getCurrentUser().sendEmailVerification().addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
progressDialog1.dismiss();
Log.d(TAG, "onSuccess: email sent");
Toast.makeText(EmailSignUpActivity.this, "Email verification sent", Toast.LENGTH_SHORT).show();
/**
* Making the app unresponsive
*/
while(!mAuth.getCurrentUser().isEmailVerified()){
mAuth.getCurrentUser().reload();
}
if(mAuth.getCurrentUser().isEmailVerified()){
Toast.makeText(EmailSignUpActivity.this, "Email verified", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(EmailSignUpActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog1.dismiss();
Log.w(TAG, "onFailure: Email verification failed ==> ", e);
}
});
}else{
Toast.makeText(EmailSignUpActivity.this, "Fill out the details", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(EmailSignUpActivity.this, "Create a user first!", Toast.LENGTH_SHORT).show();
}
}
});
The above code has a while loop after the documentation comments that would run infinitely till the email is verified but this is making the app unresponsive like:
I tried to achieve the same thing with the help of AuthStateListener but failed as AuthStateListener would only get triggered when a user is created, signed in, signed out.
authStateListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
Log.d(TAG, "onAuthStateChanged: method called");
if(firebaseAuth.getCurrentUser() != null)
isEmailVerified = firebaseAuth.getCurrentUser().isEmailVerified();
if(isEmailVerified){
Toast.makeText(EmailSignUpActivity.this, "Email verified", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(EmailSignUpActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
};
mAuth.addAuthStateListener(authStateListener);
What I want here is to listen to isEmailVerified() through a listener or any equivalent to that which shouldn't make the app unresponsive. How can I achieve this?
As you've discovered, using a so-called tight infinite loop will stop your app from responding to other user input. So we can easily agree that is a bad idea. If it was suggested that you do so in the Firebase documentation, can you give me a link to that specific piece of the documentation?
You will need to find another event to respond to, to verify that the user has verified their email address. Common options are:
Give the user a UI element to indicate they've verified their email address. This might not be possible in your situation, but it is the most common approach that I know off.
Check whether the email address is verified on startup or when your main activity show. This typically goes into your sign-in flow: sign in the user, check if their email address is verified. If so, you let them into the app. If not, you give them the option to (re)send the verification email. Given that the user will need to toggle to their mail app to get the verification email, they're already toggling out of (and thus back into) your app anyway.
Specify a so-called continue URL in with the verification email. If you use this option to send a Firebase Dynamic Link, you can automatically get the user back into your application where they left off, after they click the verification link in the email (as long as they do so on the same mobile device).
Check the periodically. This is most similar to what you do now, but then without the tight loop. See this question for some options for this: How to run a method every X seconds

Can I use Firebase "Phone Number Authentication" feature for the phone number verification purpose?

I am actually using Firebase Google auth for signing in the user and after that, I want to take the basic details of the user into the database which also includes the mobile number of a user, so my question is can use Phone Number Authentication just to verify the mobile number of user (using OTP) and after that I can store it into database?
Thank You!
If you are already signing in a user with Google. You can link/update the phone number for that user:
https://firebase.google.com/docs/reference/js/firebase.User#updatePhoneNumber
https://firebase.google.com/docs/reference/js/firebase.User#linkWithPhoneNumber
This means the user will have 2 providers linked (phone/google.com). The user will be able to sign in with either in the future. Though if you only want to expose Google as the provider. You can just provide that in your sign in page.
You can store the user in the database too.
Because Firebase Authentication is amazing,
you can have more than one authentication "method" on an account:
In this example, the app in question, allows users to create an account using either
phone
email
Facebook link
So. On the welcome screen of the app, it says "Join SuperApp, using phone, email or Facebook link!!" and there's three buttons for those three methods.
But in fact, the way Firebase Authentication works, each user can actually have more than one of those.
The third user there has both email and phone authentication. The fourth user there has all three!
So, let's say a user creates an account with "email authentication".
Later, there will be a button that says "Also link your Facebook account!",
and another one, "Also link your phone number!"
(Note that in many cases, depending on what your startup is, you may want users to have more than one authentication method, for greater security. Or, you may just want to make it easier for them to log in.)
Incredibly, Firebase can handle all that. (Or, you can spend a year developing it by hand!)
Some points...
Yes, Firebase entirely takes care of sending the email or SMS verification codes. Completely automatic.
Note that you can't "use" the amazing email/phone verification service "for other purposes". For example, in an app we're doing there's a feature where you need to verify a purchase or something, using an SMS code. Note that that has absolutely nothing to do with the user logging-in, it's just an unrelated feature in the app which uses an SMS code. You can not (unfortunately!) use Firebase's epic SMS-system to do that. (You'd just use any of the widely available sms-code-sending services, instead.)
A huge point of confusion. Note that the email and/or phone number discussed here are stored by Firebase in the Firebase Authentication system. The image above is from the Firebase Authentication system. There is NO CONNECTION AT ALL to your data tables. So, almost every app has in the data tables something like "userData/". Sure, you may, for your convenience (or whatever) have fields in the data tables like "email" "Facebook name" or whatever. Those fields have NO CONNECTION AT ALL, in any way, to the "actual, real" Firebase Authentication system (as seen in the image above). Those are just fields you populate in your development - they could hold any value you put in there. There are many, many questions here on SO where folks confuse some value "user_email" that happens to be in the database, with the "actual, real" email or phone used by Firebase in the Firebase Authentication system.
Note that if you start off with Facebook or another social authentication. Sometimes those social media have the users email/phone/etc. But that has absolutely no connection to the actual Firebase authenticated email/phone.
If the user happens to need to change their actual authenticated email or phone, there's a function for that link
The Firebase Authentication system is so amazing that many mobile projects use Firebase purely for the convenience of the amazing Firebase Authentication system, even if they are not especially using Firebase as such.
(One detail on the email front. You'll use your own email server to send the emails. (ie, godaddy or sendmail or whatever - just whatever email server you normally use.) There's a slot on the backend of Firebase where you just type in your email server/password. Alternately, during development/testing Firebase will even send the email for you, but it only arrives slowly since it's a mass-used account being used by about a zillion Firebase-app-developers like yourself.)
Summary
Amazingly you can have more than one authentication method, it is all handled by Firebase
Note that any phone/email etc you may happen to have in your data, has absolutely No connection to the "actual" phone/email in Firebase Authentication
In the Firebase console, look on the left and go one above "Database" to see "Authentication" ! Many news developers don't realize this!
If you want to use firebase phone authentication for phone number verification only, according to me you do this but by implementing following:
First in Sign-in Method page, enable the Phone Number sign-in method and to send verification code on phone number use this
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
you will get response in mCallbacks and to initialize callback use this
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// this method executed if phone number verified you can do your stuff here if you only want to verify phone number.
// or you can also use this credentials for authenticate purpose.
}
#Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
}
#Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
//and then execute your method if number entered is correct.
}
};
Don't forgot to use latest firebase dependencies like
compile 'com.google.firebase:firebase-auth:11.4.2'
Hope this will help you.
private FirebaseAuth mAuth;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
String mVerificationId = "";
PhoneAuthProvider.ForceResendingToken mResendToken;
mAuth = FirebaseAuth.getInstance();
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks()
{
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
//edtVerify.setText(phoneAuthCredential.getSmsCode());
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Log.e("Invalid Phone Number ","====>");
} else if (e instanceof FirebaseTooManyRequestsException) {
Log.e("Quota exceeded ","====>");
}
}
#Override
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken token) {
mVerificationId = verificationId;
mResendToken = token;
}
};
//SEND VERIFICATION CODE...
try {
PhoneAuthProvider.getInstance().verifyPhoneNumber(mLastEnteredPhone, 120,
TimeUnit.SECONDS,
mContext,
mCallbacks);
} catch (Exception e) {
e.printStackTrace();
}
//VERIFY CODE...
try {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
signInWithPhoneAuthCredential(credential);
} catch (Exception e) {
e.printStackTrace();
}
//SIGN IN WITH PHONE...
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential)
{
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful())
{
FirebaseUser user = task.getResult().getUser();
String currentUid = user.getUid();
String currentPhone = user.getPhoneNumber();
} else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Log.e("Invalid Code ","====>");
}
}
}
});
}
Yes you can use it with the help of following code
PhoneAuthProvider.getInstance().verifyPhoneNumber(
mobnum, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationId=s;
}
#Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(getApplicationContext(),"Verification Failed"+e.getMessage(),Toast.LENGTH_LONG).show();
}
}); // OnVerificationStateChangedCallbacksPhoneAuthActivity.java
after that you have to use the following method
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
firebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent i = new Intent(Otp_Verification_Activity.this,HomeActivity.class);
startActivity(i);
finish();
} else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
}
}
}
});
}
and for more you can visitclickhere
and you watch video on youtube clickhere

User Firebase Phone Auth

Is it possible to use Phone Auth just to verify a phone number? My users are already logged in with other providers. I only need to make sure that the number they have entered is valid.
You can do this using Firebase's PhoneAuthProvider which will send sms of one time code to the user phone number through which the user is verified.
The implementation is given in this documentation: Firebase phone authentication
lets say that You can't verify the phone number without creating a new user linked to this number in firebase using the manual verification
but you can unlink the phone from the user account soon after, by calling:
FirebaseAuth.getInstance().getCurrentUser().
unlink(PhoneAuthProvider.PROVIDER_ID)
.addOnCompleteListener(this);
just like:
final PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, scode);
mAuth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseAuth.getInstance().getCurrentUser().
unlink(PhoneAuthProvider.PROVIDER_ID)
.addOnCompleteListener(this);
register_user(sname,semail,sphone,scode, spass); // this if you wanna register with a different method
}
}
});
And There is the possibility of auto verification of Google Play Services (in the new phones). When onVerificationCompleted(PhoneAuthCredential) in your PhoneAuthProvider.OnVerificationStateChangedCallbacks is called. and here the verification is completed with no need from the user to type anything and the phone will not linked to a new user account.
PhoneAuthProvider.getInstance().verifyPhoneNumber(sphone, 60, TimeUnit.SECONDS, AuthActivity.this, new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
register_user(sname,semail,sphone,scode, spass); // this if you wanna register with a different method
}
#Override
public void onVerificationFailed(FirebaseException e) {
}
#Override
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken token) {
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
// ...
}
});
I think that google should allow to the developers to verify the phone without creating user account that will be so helpful

Firebase phone Auth for Android , Can we just verify phone number without creating a user account

I am working on an android app, in where I just want to verify mobile number without creating a user account. Is it Possible? I am using the following code
private void startPhoneNumberVerification(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
}
private void verifyPhoneNumberWithCode(String verificationId, String code) {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
signInWithPhoneAuthCredential(credential); // this function is creating user account , if not present. But We Don't want this
}
The following function will create user account if user account is not there, but I don't want to create account, I just want to verify the code entered by the user. Is there any call back method available for that?
private void signInWithPhoneAuthCredential(final PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
dialog.dismiss();
FirebaseUser user = task.getResult().getUser();
Toast.makeText(LoginActivity.this, "Success " + user.getEmail(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(LoginActivity.this, "Failed ", Toast.LENGTH_SHORT).show();
verifyPhoneNumberWithCode(mVerificationId, editText.getText().toString().trim());
}
}
});
}
You can't verify what the user typed without linking the phone provider to the Firebase user in the process.
But you can unlink the phone from the user account soon after, by calling:
FirebaseAuth.getInstance().getCurrentUser().
unlink(PhoneAuthProvider.PROVIDER_ID)
.addOnCompleteListener(this, onCompleteListener);
There are plenty of uses for verifying that the user has access to this phone number, but shouldn't login with it. I really think that Firebase should allow developers to verify first, and use the credential to login after.
Also:
There is a good chance of Google Play Services verifying automatically. When onVerificationCompleted(PhoneAuthCredential) in your PhoneAuthProvider.OnVerificationStateChangedCallbacks is called. This way the user won't need to type the verification code, and the phone won't be linked automatically.
Verifying a phone number automatically creates a Firebase Authentication account for that user. There is no way to prevent creating this account, as it is what Firebase uses to ensure it knows that user next time they start the app.
You can also update the phone number on the user account.
This will not create new user; instead, it will update the phone number in the existing user account.
val credential = PhoneAuthProvider.getCredential(verificationId!!, smsCode)
FirebaseAuth.getInstance().currentUser?.updatePhoneNumber(credential)

Categories

Resources