I am trying to create an app in which after a user types his email/ password they are saved in the firebase then the user enters his phone number on which otp is sent and the user is logged in after verification.my problem is that when both of these steps are completed firebase is creating two separate accounts one with email other with the phone. Please Tell me how can I create a Single account with Both Email/Password and Phone.
If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.
Finding the Password Hash Parameters To access these parameters, navigate to the 'Users' tab of the 'Authentication' section in the Firebase Console and select 'Password Hash Parameters' from the drop down in the upper-right hand corner of the users table.
Since you are using multiple Firebase authentication providers then you need to link them, so both phone and email will create on single account.
First you can get the credentials:
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
then using linkwithCredentials()
you will be able to link them:
mAuth.getCurrentUser().linkWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "linkWithCredential:success");
FirebaseUser user = task.getResult().getUser();
updateUI(user);
} else {
Log.w(TAG, "linkWithCredential:failure", task.getException());
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// ...
}
});
more info here:
https://firebase.google.com/docs/auth/android/account-linking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With