【发布时间】:2018-02-21 12:09:10
【问题描述】:
我使用 firebase admin sdk 设置了自定义声明。我已经成功地使用它来控制前端甚至 RTDB 的访问,但我无法将它与 Firestore 数据库一起使用。这是我的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.token.admin == true;
}
}
}
这是我的应用程序中的代码:
const users = []
firebase.firestore().collection('users')
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
users.push(doc.data())
})
})
.then(() => {
commit('setUsersList', users)
commit('setLoading', false)
})
.catch(function (error) {
console.log('Error getting documents:', error)
commit('setLoading', false)
})
这是我得到的错误:
Error: Missing or insufficient permissions
【问题讨论】:
-
请添加导致错误的代码
-
嗨。我用我的应用代码编辑了我的问题
-
Cloud Firestore Security Rules Reference 文档指出“如果使用自定义身份验证,request.auth.token 还包含开发人员指定的任何自定义声明。”因此,除非您的令牌中缺少管理员声明/不正确,或者我缺少某些内容,否则我不明白为什么它不起作用。希望其他人可能有答案
-
能否强制刷新用户的 ID 令牌?根据我的询问,可能需要让自定义声明显示在安全规则中。
-
我用
getIdToken(true)做了一个刷新令牌,但我仍然遇到同样的错误。 :(
标签: firebase google-cloud-firestore firebase-security