我已经设置了一个Firebase项目,我正在使用它的用户身份验证模块。我也在使用Github的firebaseui-web项目。
根据以下代码,我的登录重定向工作正常:
// FirebaseUI config.
var uiConfig = {
'signInSuccessUrl': 'MY_REDIRECT.html',
'signInOptions': [
firebase.auth.EmailAuthProvider.PROVIDER_ID
],
// Terms of service url.
'tosUrl': '<your-tos-url>',
};
当页面加载时(即MY_REDIRECT.html)我正在检查用户的状态以查看他们是否已经验证了他们的电子邮件,如果没有,则调用sendEmailVerification
method:
checkLoggedInUser = function() {
auth.onAuthStateChanged(function(user) {
if (user) {
// is email verified
if(user.emailVerified) {
// show logged in user in UI
$('#loggedinUserLink').html('Logged in:' + user.email + '<span class="caret"></span>');
} else {
// user e-mail is not verified - send verification mail and redirect
alert('Please check your inbox for a verification e-mail and follow the instructions');
// handle firebase promise and don't redirect until complete i.e. .then
user.sendEmailVerification().then(function() {
window.location.replace('index.html');
});
}
} else {
// no user object - go back to index
window.location.replace("index.html");
}
}, function(error) {
console.log(error);
});
};
window.onload = function() {
checkLoggedInUser()
};
到目前为止一切都很好 - Firebase正在做我想要的!多谢你们 :)
但是,在Firebase控制台界面中,似乎没有办法查看用户是否实际访问了其收件箱并单击了链接以执行验证。用户界面如下所示:
我已经运行了基本测试,用户UID在验证发生之前和之后都没有变化。
所以,这是我的问题 - 我是否正确地进行了电子邮件验证?如果是这样(因此UI没有显示我验证与未验证)是否有一种可接受的方法来访问Auth模块中的这两组用户?我无法看到访问UID及其属性(包括emailVerified
属性)的基础表的方法。如果功能不在控制台中,我不介意编写更多代码 - 只是想在下一步中按正确方向轻推。
Firebase控制台目前无法查看特定用户的电子邮件地址是否已经过验证。有一个API to get a list of users,但你不能过滤它们是否经过验证。
您可以检查当前经过身份验证的用户的电子邮件地址是否经过验证:
firebase.auth().currentUser.emailVerified
你不能阻止谁报名。但您可以轻松确保只有拥有经过验证的电子邮件地址的用户才能访问(某些)数据。例如:
{
"rules": {
".read": "auth != null && auth.token.email_verified",
"gmailUsers": {
"$uid": {
".write": "auth.token.email_verified == true &&
auth.token.email.matches(/.*@gmail.com$/)"
}
}
}
}
上述规则确保只有具有经过验证的电子邮件地址的用户才能读取任何数据,并且只有具有经过验证的Gmail地址的用户才能在gmailUsers
下写入。