我已经使用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);
但出于安全原因,我希望用户从上面的代码中确认她/他的email.But,它不会向用户发送验证邮件。所以我使用了以下方法,如果用户没有验证他/她的账号邮件,我会发送一封验证邮件给他/她。
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的特定用户发送了验证邮件,那就太好了。
发布于 2019-03-17 17:15:18
我在示例代码here中找到了对这个几乎没有文档记录(对于JavaScript)的Firebase问题的更好的解决方案
// FirebaseUI config.
var uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
var user = authResult.user;
...
if (authResult.additionalUserInfo.isNewUser)
{
console.log("new signin");
user.sendEmailVerification();
}
...
return true;
},
享受吧!
发布于 2018-06-04 16:52:09
我迟到了,但如果有人发现它像我一样:
if(currentUser.metadata.creationTime === currentUser.metadata.lastSignInTime)
如果是新用户,则为true,因此您必须发送验证电子邮件。你也可以在signInSuccess中做,不需要在onAuthStateChanged上寻找
发布于 2018-06-06 07:48:26
您可以使用SignInSuccessWithAuthResult
回调发送验证邮件。您需要做的是提供一个回调函数,并检查用户是否验证了电子邮件,如果没有,则执行sendEmailVerification。
https://stackoverflow.com/questions/43409932
复制相似问题