AngularFirestore 的权限缺失或不足
Missing or insufficient permissions with AngularFirestore
当我尝试从 Firestore(angular@12.0.3 和 angular/fire@6.1.5)获取文档时出现以下错误:
ERROR FirebaseError: Missing or insufficient permissions.
根据firebase的手册,我写了firestore的规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /collection/document {
allow read: if request.auth != null;
allow write: if false;
}
}
}
这是我的服务代码:
constructor(
private store: AngularFirestore,
private db: AngularFireDatabase,
private auth: AuthService
) {
// this.auth.user$ = this.angularFireAuth.user
this.auth.user$.subscribe(user => {
if (user && user.email) {
this.store.doc('/collection/document').valueChanges().subscribe(_ => {
console.log(_); // throws ERROR FirebaseError: Missing or insufficient permissions.
});
this.db.list<List>(`lists`, ref => ref.orderByChild('owner').equalTo(user.email))
.valueChanges([], {idField: 'uuid'})
.subscribe(_ => {
console.log(_); // works fine
})
}
});
}
我对 firebase 规则有点熟悉,所以订阅 rtdb 工作正常(使用生产就绪规则)。如果我用 allow read: if true;
更改读取规则,我可以从 firestore 集合接收数据,但当然我希望规则更严格。所以问题看起来 request.auth
in rules seems to equal null without applicable reason.
谢谢大家的帮助!
尝试将规则中的 match /collection/document
修改为 match /collection/{document}
。
问题出在 firebase 包中:
https://github.com/angular/angularfire/issues/2838
更新我的所有包后我确实遇到了同样的问题(angular 12,angular/fire,firebase)当我降级 firebase 包时解决了这个问题:
npm i firebase@8.6.1
当我尝试从 Firestore(angular@12.0.3 和 angular/fire@6.1.5)获取文档时出现以下错误:
ERROR FirebaseError: Missing or insufficient permissions.
根据firebase的手册,我写了firestore的规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /collection/document {
allow read: if request.auth != null;
allow write: if false;
}
}
}
这是我的服务代码:
constructor(
private store: AngularFirestore,
private db: AngularFireDatabase,
private auth: AuthService
) {
// this.auth.user$ = this.angularFireAuth.user
this.auth.user$.subscribe(user => {
if (user && user.email) {
this.store.doc('/collection/document').valueChanges().subscribe(_ => {
console.log(_); // throws ERROR FirebaseError: Missing or insufficient permissions.
});
this.db.list<List>(`lists`, ref => ref.orderByChild('owner').equalTo(user.email))
.valueChanges([], {idField: 'uuid'})
.subscribe(_ => {
console.log(_); // works fine
})
}
});
}
我对 firebase 规则有点熟悉,所以订阅 rtdb 工作正常(使用生产就绪规则)。如果我用 allow read: if true;
更改读取规则,我可以从 firestore 集合接收数据,但当然我希望规则更严格。所以问题看起来 request.auth
in rules seems to equal null without applicable reason.
谢谢大家的帮助!
尝试将规则中的 match /collection/document
修改为 match /collection/{document}
。
问题出在 firebase 包中: https://github.com/angular/angularfire/issues/2838
更新我的所有包后我确实遇到了同样的问题(angular 12,angular/fire,firebase)当我降级 firebase 包时解决了这个问题:
npm i firebase@8.6.1