I've problem with firebase password-less authentication. My app enables users to sign in with phone number or with email link.
The user's account in firebase loses it's phone number when trying to sign in by signInWithEmailLink, while he logged in successfully though.
Here's the piece of code which executed when the user is redirected from his mail to the app through the dynamic link:
FirebaseDynamicLinks.getInstance()
.getDynamicLink(activity.getIntent())
.addOnSuccessListener(activity, pendingDynamicLinkData -> {
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
String emailLink = deepLink.toString();
String authEmail = activity.getPreferences(Context.MODE_PRIVATE).getString("link_auth_email",null);
if(authEmail != null){
Helper.showProgressDialog(activity);
firebaseAuth.signInWithEmailLink(authEmail,emailLink).addOnCompleteListener(activity,task ->{
if(task.isSuccessful()){
firebaseUser = task.getResult().getUser();
name = firebaseUser.getDisplayName();
phone = firebaseUser.getPhoneNumber();
email = firebaseUser.getEmail();
image = firebaseUser.getPhotoUrl();
firebaseUser.getIdToken(true).addOnCompleteListener(activity, task1 -> {
Helper.hideProgressDialog();
if(task1.isSuccessful()){
token = task1.getResult().getToken();
}else if(task1.getException() !=null){
Toast.makeText(activity, task1.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
});
}else{
Helper.hideProgressDialog();
Toast.makeText(activity, "Authentication failed. "+(task.getException().getMessage()==null?"":task.getException().getMessage()), Toast.LENGTH_SHORT).show();
}
});
}
}
else{
firebaseUser = firebaseAuth.getCurrentUser();
if(firebaseUser != null){
name = firebaseUser.getDisplayName();
phone = firebaseUser.getPhoneNumber();
email = firebaseUser.getEmail();
image = firebaseUser.getPhotoUrl();
firebaseUser.getIdToken(true).addOnCompleteListener(activity, task -> {
if(task.isSuccessful()){
token = task.getResult().getToken();
}else if(task.getException() !=null){
Toast.makeText(activity, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
})
.addOnFailureListener(activity, e -> Toast.makeText(activity, "Link failure: "+e.getMessage(), Toast.LENGTH_SHORT).show());
Firebase dependencies:
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.firebase:firebase-dynamic-links:19.0.0'
implementation 'com.google.firebase:firebase-analytics:17.4.4'
This was because I added email to user in signup through updateEmail method after phone authentication progress instead of using linkwithcredential
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