【发布时间】:2021-01-31 17:21:50
【问题描述】:
我已在 firebase 中应用了该规则。在firestore auth中添加了一个用户并相应地更改了规则。我的自定义firestore规则是
match /{document=**} {
allow read, write :if request.auth == 'Here user values will add';
从我的nestjs代码中,用户作为头文件添加到控制器类中,并将这个值传递给服务层,但是当在我们的firebase服务类中传递这个值时,这是我在firebase服务类中的以下代码。
下面是我的控制器类
@Get('/list')
async getDocumentList(@Headers('user') user: string): Promise<any> {
console.log("controller"+user);
try {
return await this.incidentService.getIncidentList(user);
} catch (e) {
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
}
}
firestore 服务类是:-
async getDocumentList(collectionName: string,user ): Promise<any> {
console.log(user);
const docSnapshot = await firestore().collection(collectionName).get();
const docList = [];
docSnapshot.forEach(doc => {
docList.push(doc.data());
});
return docList;
}
我想知道如何将用户值传递/通知或设置条件到 firestore,以便将此用户值设为管理员并根据此值应用规则?
Firestore 服务类中的代码是什么?
【问题讨论】:
标签: typescript google-cloud-firestore firebase-security