未发送Firebase确认电子邮件
我已成功设置Firebase电子邮件/密码身份验证,但出于安全原因,我希望用户确认其电子邮件。 Firebases网站上说: 当用户使用电子邮件地址和密码注册时,将发送确认电子邮件以验证其电子邮件地址 但当我注册时,我没有收到确认电子邮件 我已经看过了,只能找到发送密码重置电子邮件的代码,但找不到发送电子邮件确认的代码 我在这里看过:未发送Firebase确认电子邮件,firebase,authentication,firebase-authentication,email-verification,Firebase,Authentication,Firebase Authentication,Email Verification,我已成功设置Firebase电子邮件/密码身份验证,但出于安全原因,我希望用户确认其电子邮件。 Firebases网站上说: 当用户使用电子邮件地址和密码注册时,将发送确认电子邮件以验证其电子邮件地址 但当我注册时,我没有收到确认电子邮件 我已经看过了,只能找到发送密码重置电子邮件的代码,但找不到发送电子邮件确认的代码 我在这里看过: 有人知道我该怎么做吗?我注意到新的Firebase电子邮件身份验证文档没有正确记录 firebase.auth().onAuthStateChanged(fun
有人知道我该怎么做吗?我注意到新的Firebase电子邮件身份验证文档没有正确记录
firebase.auth().onAuthStateChanged(function(user) {
user.sendEmailVerification();
});
请注意:
firebase.auth().onAuthStateChanged(function(user) {
if (user.emailVerified) {
console.log('Email is verified');
}
else {
console.log('Email is not verified');
}
});
您可以向AuthListener发送验证电子邮件并检查是否已验证,如下所示:
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
//---- HERE YOU CHECK IF EMAIL IS VERIFIED
if (user.isEmailVerified()) {
Toast.makeText(LoginActivity.this,"You are in =)",Toast.LENGTH_LONG).show();
}
else {
//---- HERE YOU SEND THE EMAIL
user.sendEmailVerification();
Toast.makeText(LoginActivity.this,"Check your email first...",Toast.LENGTH_LONG).show();
}
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// [START_EXCLUDE]
updateUI(user);
// [END_EXCLUDE]
}
};
如果您正在使用compile“com.google.firebase:firebase auth:9.2.0”和
编译'com.google.firebase:firebase core:9.2.0'方法sendEmailVerification()将在更新到9.8.0或更高版本之前无法解析。在我弄明白之前,它浪费了大部分时间。创建用户后,将返回一个用户对象,您可以在其中检查用户的电子邮件是否已被验证 当用户尚未验证时,您可以在用户对象本身上触发sendEmailVerification方法
firebase.auth()
.createUserWithEmailAndPassword(email, password)
.then(function(user){
if(user && user.emailVerified === false){
user.sendEmailVerification().then(function(){
console.log("email verification sent to user");
});
}
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode, errorMessage);
});
您还可以通过侦听AuthState进行检查,以下方法的问题是,对于每个新会话(通过刷新页面),
将发送一封新电子邮件
firebase.auth().onAuthStateChanged(function(user) {
user.sendEmailVerification();
});
我也一直在看这个。看起来firebase已经改变了你发送验证的方式。对我来说
user.sendEmailVerification()
不起作用。
如果出现错误,例如user.sendmailverification()不存在。
使用以下命令
firebase.auth().currentUser.sendEmailVerification()
您可以向其电子邮件链接到Firebase Auth帐户的任何用户发送验证电子邮件。例如,在flatter中,您可以执行以下操作。比如:
Future<void> signInWithCredentialAndLinkDetails(AuthCredential authCredential,
String email, String password) async {
// Here authCredential is from Phone Auth
_auth.signInWithCredential(authCredential).then((authResult) async {
if (authResult.user != null) {
var emailAuthCredential = EmailAuthProvider.getCredential(
email: email,
password: password,
);
authResult.user
.linkWithCredential(emailAuthCredential)
.then((authResult,onError:(){/* Error Logic */}) async {
if (authResult.user != null) {
await authResult.user.sendEmailVerification().then((_) {
debugPrint('verification email send');
}, onError: () {
debugPrint('email verification failed.');
});
}
});
}
});
}
Future Sign With Credential身份认证链接详细信息(AuthCredential AuthCredential,
字符串电子邮件,字符串密码)异步{
//这里authCredential来自电话验证
_auth.signInWithCredential(authCredential)。然后((authResult)异步{
if(authResult.user!=null){
var emailAuthCredential=EmailAuthProvider.getCredential(
电邮:电邮,,
密码:密码,
);
authResult.user
.linkWithCredential(emailAuthCredential)
.then((authResult,onError:(){/*错误逻辑*/})异步{
if(authResult.user!=null){
等待authResult.user.sendEmailVerification()。然后((){
调试打印(“验证电子邮件发送”);
},onError:(){
debugPrint('电子邮件验证失败');
});
}
});
}
});
}
这不是问题的答案,但可能对某人有所帮助。
别忘了将您的站点域添加到登录方法下的授权域列表中谢谢,我一直在寻找这个答案,您知道如何检查电子邮件是否已确认吗?firebase.auth().onAuthStateChanged(函数(user){(user.emailVerified)→console.log('email已验证'):console.log('email未验证');firebaser这里回答得很好@XavierJ.Wong。我添加了一个注释,我们需要将其添加到文档中。@FrankvanPuffelen仍然不在文档中。“授权电子邮件模板”页面中很好地说明了这一点,但除了这个答案之外,没有任何文档可供参考。@FrankvanPuffelen我一直不明白如何创建“google.com”具有非Google电子邮件地址的帐户-并且
emailVerified
标志将返回false,但尝试sendEmailVerification
不会做任何事情。是否有任何方法可以区分这种情况,以便我们可以忽略验证状态?或者这是Firebase中的一个bug?您链接到了iOS文档,但接受的答案使用JavaScript。您使用的是哪一个(以便我可以重新标记问题以匹配使用的平台)?我似乎无法在Android版本中找到.sendEmailVerification()。有人在Android上的Firebase中使用过电子邮件验证吗?缺少启动电子邮件验证流的API。电子邮件地址验证目前是iOS和Web上的一项实验性功能。使用新API,如何检查用户是否已验证?sendmailverification()
aftercreateUserWithEmailAndPassword
不起作用。当时user.emailverified
是undefined
。发送电子邮件应始终在AuthStateChanged上进行调用createUserWithEmailAndPassword(…)。然后接收一个firebase.auth.UserCredential
,而不是firebase.User
。只需使用then(credential=>credential.user.emailVerified…
。@Andy:根据,我使用then((userRecord)=>{userRecord.user.sendmailverification()…})
,但它说无法读取未定义的属性“sendmailverification”。