【发布时间】:2021-05-20 08:13:26
【问题描述】:
今天,我正在阅读有关 Firestore 安全规则的内容,
我看到使用 **"request.resource.auth"** 和 **"request.auth"** 检查身份验证规则的情况。
我想知道与他们有什么不同?
以下是关于这些示例:
service cloud.firestore {
match /databases/{database}/documents {
// Allow any logged in user to view the public employee data
match /employees/{emp_id} {
allow read: if request.resource.auth != null
// Allow only users with the custom auth claim of "Finance" to view
// the employee's financial data
match /private/finances {
allow read: if request.resource.auth &&
request.resource.auth.token.role == 'Finance'
}
}
}
}
和
service cloud.firestore {
match /databases/{database}/documents {
// Allow the user to access documents in the "cities" collection
// only if they are authenticated.
match /cities/{city} {
allow read, write: if request.auth != null;
}
}
}
谢谢!
【问题讨论】:
标签: firebase google-cloud-firestore firebase-authentication firebase-security