我一直在尝试从 firestore 读取数据,但无法读取...
async authUser() {
let token = this._tokman.getUserToken();
await this._afa.signInWithCustomToken(token);
}
从服务器获取令牌并将其传递给 firebase 以验证用户身份。 然后调用firestore获取数据..
async data() {
await this._afa.onAuthStateChanged(user => {
if (user) {
this._afs.collection('gps-data').doc(user.uid)
.valueChanges()
.subscribe(res => {
console.log(res);
}, err => {
console.log(err);
})
}
})
}
但是从 firestore 得到这个错误。
FirebaseError: Missing or insufficient permissions.
at new e (http://localhost:4200/vendor.js:51950:23)
at http://localhost:4200/vendor.js:62177:28
at http://localhost:4200/vendor.js:62178:18
at e.onMessage (http://localhost:4200/vendor.js:62200:10)
at http://localhost:4200/vendor.js:62117:26
at http://localhost:4200/vendor.js:62148:37
at http://localhost:4200/vendor.js:66953:31
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:460:30)
at Zone.run (http://localhost:4200/polyfills.js:219:47)
at http://localhost:4200/polyfills.js:953:40
Firestore 安全规则是
service cloud.firestore {
match /databases/{database}/documents {
match /gps-data/{userid} {
allow read: if request.auth.token.sub == userid;
}
}
}
还将 jwt 令牌添加到 http 标头。 请指导我哪里做错了。
更新 解决方法:更改 firebase 版本 来自
"firebase": "^7.0 || ^8.0"
致
"firebase": "^8.0.2"
不改变安全规则