我已使用firebase-ui成功设置了Firebase电子邮件/密码身份验证 .
var uiConfig = {
signInSuccessUrl: '<?php echo $url; ?>',
signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID
],
// Terms of service url.
tosUrl: '<your-tos-url>'
};
// Initialize the FirebaseUI Widget using Firebase.
var ui = new firebaseui.auth.AuthUI(firebase.auth());
// The start method will wait until the DOM is loaded.
ui.start('#firebaseui-auth-container', uiConfig);
但出于安全考虑,我希望用户确认她/他的电子邮件 . 但是从上面的代码来看,它不会向用户发送验证邮件 . 因此,如果用户未验证他/她的帐户邮件,我会使用以下方法向用户发送验证邮件 .
firebase.auth().onAuthStateChanged(function(user) {
if (user && user.uid != currentUid) {
if (firebase.auth().currentUser.emailVerified) {
currentUid = user.uid;
else {
//---- HERE YOU SEND THE EMAIL
firebase.auth().currentUser.sendEmailVerification();
}
但是,当我使用此代码时,它会为同一帐户发送多个验证邮件 . 这意味着每次用户重新加载页面时都会运行此方法 . 如果有人可以帮助我确定是否使用firebase为特定用户发送验证邮件,那将是非常好的 .
2 回答
我迟到但如果有人发现它像我一样:
当它是新用户时是真的,因此您必须发送验证电子邮件 . 您也可以在signInSuccess中执行此操作,无需查看onAuthStateChanged
您可以使用
SignInSuccessWithAuthResult
回调来发送电子邮件验证 . 您需要做的是提供回调函数并检查用户是否已验证电子邮件,如果没有,则发送sendEmailVerification .