firebase - Firestore 安全规则 email_verified 不起作用
问题描述
如果我创建一个新用户createUserWithEmailAndPassword
,即使我还没有验证邮件,该用户已经登录。他的.emailVerified === false
,直到这里一切都好。
现在,我去邮件,使用链接验证它,回到网络应用程序,它仍然是.emailVerified === false
所以我刷新页面,现在.emailVerified === true
。
所以我尝试联系这个文档:
public async getPublicUserDetails() {
const currentUserId = this._angularFireAuth.auth.currentUser.uid;
try {
const docRef = this._angularFirestore.collection("users").doc(currentUserId).ref;
const doc = await docRef.get();
if (!doc.exists) {
return null;
}
return doc.data() as IPublicUserDetailsDto;
}
catch (error) {
console.error("User " + currentUserId + " details get failed! " + JSON.stringify(error));
throw error;
}
}
它捕获一个异常,说我没有访问文档所需的权限。
我使用的 Firestore 规则是:
rules_version = '2';
service cloud.firestore {
function dbDocs() { return /databases/$(database)/documents; }
function isSignedIn() { return request.auth != null && request.auth.uid != null; }
function isEmailVerified() { return isSignedIn() && request.auth.token.email_verified; }
function isCurrUser(uid) { return isSignedIn() && request.auth.uid == uid; }
function userExists(uid) { return exists(/databases/$(database)/documents/users/$(uid)); }
match /databases/{database}/documents {
match /users {
match /{userId} {
allow read: if isEmailVerified();
allow write: if isEmailVerified() && isCurrUser(userId);
}
}
}
}
我可以无限次刷新页面,但只有当我再次注销和登录或allow read
将行 替换为
match /{userId} {
allow read: if isSignedIn(); // replace this
allow write: if isEmailVerified() && isCurrUser(userId);
}
结论:似乎request.auth.token.email_verified
没有反映FirebaseAuth
服务内部提供的值,因为它似乎只有在我注销并重新登录时才会刷新。
有人能帮助我吗?谢谢大家!
解决方案
推荐阅读
- ebpf - 如何使用 eBPF (BCC) 跟踪 Java 进程
- android - Flutter AppCenter Gradle Plugin 4.0.0+ 构建问题
- java - Spring Boot 项目(GET-endpoints)中接口 URL 的正确位置?
- sql - 从一个表中获取一个字段并查看另一个表中是否存在包含该字段的条目的脚本
- opengl - 只更新片段着色器中的统一值而不重绘所有内容 - 可能吗?
- azure - 如何从 Azure 容器注册表(站点到站点连接)中提取 Ubuntu 服务器中的 docker 映像?
- terminal - 使用 find 排除所有子目录
- python - 使用 python 用 solr 中的动态值更新字段值
- joomla3.0 - 如何将数字更改为 idcardnumber 46051480Y --> 通过 XXXXXXX480y --> 使用 calc 元素
- jira-rest-api - JIRA 身份验证 API - Python