Firebase云存储规则可否针对Firestore数据进行验证?

问题描述:

我们是否可以使用Firestore数据来授予或限制访问Firebase云存储上托管的文件?Firebase云存储规则可否针对Firestore数据进行验证?

为例的,我想作为火力地堡安全规则

allow write: if get(/databases/mydbname/documents/guilds/$(guildID)).data.users[(request.auth.uid)] in ["Admin", "Member"]; 

目前还没有办法从其他产品的安全规则内访问不同的火力地堡的产品使用什么。见:is there a way to authenticate user role in firebase storage rules?

但它似乎是你试图检查用户的组成员资格。我建议您将其建模为所谓的自定义声明,而不是将其视为数据库中的组成员。代替(或补充)写的会员数据库,你会set the claim "user {uid} is a member of group {guild1}" into the user profile using the Firebase Admin SDK

admin.auth().setCustomUserClaims(uid, {guild1: true}).then(() => { 
    // The new custom claims will propagate to the user's ID token the 
    // next time a new one is issued. 
}); 

做完这些后,你可以在安全规则检查公会成员:

allow read: if request.auth.token.guild1 == true; 

(我不确定是否/如何将公会会员制作为地图,如果事实证明是这样,我会更新此答案。)

+0

有意义。将尝试使用云端firestore触发器填充基于数据库的自定义声明,并会看到是否会生成它 – Remi