I am using ionic 3 and firebase authentication using facebook. The facebook does not return email id if user did not provided one while signup or did not verify it at all.
Our system mandates providing of email id. So, as a fall back we prompt user to provide the email id. As we let user manually provide the email id at this step so there is a need to verify it.
It seems firebase auth sendEmailVerifcation required the email id already in the auth. As our case is specifically handling when this is missing so how can we use this feature to validate the email id?
Any other ideas are welcome too to handle it. It is a critical blocker for us as people are misusing our reward system by providing fake email ids.
I have looked into the sendEmailVerification api but it does not seem to accept any parameter to manually pass the email id.
constructor(public navCtrl: NavController,
public navParams: NavParams,
private afAuth: AngularFireAuth,
private fb: Facebook,
private platform: Platform,
private core:CoreProvider,
public viewCtrl: ViewController,
private ddlSvc: DoodleDataProvider,
private alertCtrl:AlertController,
private toastCtrl: ToastController) {
//block back button on android
platform.registerBackButtonAction(() => {
},1);
afAuth.authState.subscribe(user => {
console.log("auth subscription finished: with user:" + JSON.stringify(user))
//go back if user could not be retrieved or manual logout is set to true
if (!user || core.manualLogout == true) {
return;
}
user.sendEmailVerfication() //problem here when email is null
console.log("initializing user")
this.createUser(user.uid)
});
}
2
Answers
Email verification is only for users who sign up with email/password authentication. The purpose is to validate that the user gave a valid email address at the time they signed up. You typically want to use email verification after you sign in the user with
firebase.auth().createUserWithEmailAndPassword()
.Email verification is not available for other authentication providers (such as Facebook), since they have their own way to managing their users’ email addresses.
As you noted,
sendEmailVerifcation
works only for the email that’s configured in the auth user object, you can’t send an email verification to a custom email.What you can do especially in the case the email was originally
null
, is to update the auth user email with the email address you prompted them to input, before sending the verification email: