是否可以使用 Firebase 的 firestore 设置存储规则? [英] Is it possible to set storage rules using firestore of Firebase?

查看:18
本文介绍了是否可以使用 Firebase 的 firestore 设置存储规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试将规则设置到存储中,但我需要访问 firestore 才能正确设置.

So I'm trying to set rules into storage, but I need to access to firestore to set it right.

这是我的例子:

在我的 firestore 数据库中,我有一个 users 集合,其中有一个名为 items 的集合.路径如下所示:/users/items/{itemId}

Into my firestore database I have a users collection which have a collection named items. The path look like this: /users/items/{itemId}

我希望用户可以使用以下路径读取和写入文件到存储中:/items/{id}/file.png 仅当 {id}项目的 已存在于 firestore 数据库的 items 集合中.有没有办法使用 firestore 将正确的规则设置到存储中?

I want that a user can read and write a file into storage with this path: /items/{id}/file.png only if the {id} of the item already exist into the items collection of firestore database. Is there a way to set correctly rules into storage using firestore ?

我试过了:

service firebase.storage {
  match /b/{bucket}/o {
    match /items/{item}/{allPaths=**} {
        allow read, write: if exists(/databases/{database}/documents/users/$(request.auth.uid)/items/$(item));
    }
  }
}

但这不起作用:/

感谢您的帮助!

推荐答案

一个 Firebase 产品的安全规则无法引用另一个 Firebase 产品.性能影响太大.

There is no way for security rules of one Firebase product to refer to another Firebase product. The performance implications would be too big.

如果您需要此类产品间一致性,您可能需要考虑从 Cloud Functions 执行写入操作.虽然这不会突然允许跨产品安全规则,但它确实意味着您要确保是您的代码进行写入,并且代码在比普通用户的手机或手机更可靠的环境中运行.电脑.

If such inter-product consistency is a requirement for you, you might want to consider doing the writes from Cloud Functions. While that doesn't suddenly allow cross-product security rules, it does mean that you an ensure it is your code doing the writes and the code is running in a more reliable environment then the average user's phone or PC.

这篇关于是否可以使用 Firebase 的 firestore 设置存储规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆