我希望我的用户只能读取和写入他自己的数据,但是。当我测试规则时,我收到消息“模拟器读取被拒绝”。请告诉我哪里错了?感谢您抽出时间。
这里有一些信息:
规则
service firebase.storage {
// Only a user can upload their file, but anyone can view it
match /users/{userId}/{fileName} {
allow read ;
allow write: if request.auth != null && request.auth.uid == userId;
}
}
地点
/b/online-notepad-d43d2.appspot.com/o/WkqtgpdUYRUGOBaAfmCByXtVPoT2/file1.txt
提供商
"password"
FIREBASE UID
WkqtgpdUYRUGOBaAfmCByXtVPoT2
电子邮件
电子邮件已验证
true
身份验证负载
{
"uid": "WkqtgpdUYRUGOBaAfmCByXtVPoT2",
"token": {
"sub": "WkqtgpdUYRUGOBaAfmCByXtVPoT2",
"aud": "online-notepad-d43d2",
"email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="325a5553474005020372555f535b5e1c515d5f" rel="noreferrer noopener nofollow">[email protected]</a>",
"email_verified": true,
"firebase": {
"sign_in_provider": "password"
}
}
}
屏幕截图
我正在使用的确切位置:“/WkqtgpdUYRUGOBaAfmCByXtVPoT2/file1.txt” 另一件事是我通过上传按钮上传此文件夹和文件。 不是来自 POST 请求。
仍然得到相同的结果:(
最佳答案
这里定义了两个完全独立的子句:
allow read ;
allow write: if request.auth != null && request.auth.uid == userId;
因此,您有一个空的读取子句和一个非空的写入子句。
您可能想使用:
allow read, write: if request.auth != null && request.auth.uid == userId;
编辑第二个问题:正如您在编辑中所说,您正在访问路径 /WkqtgpdUYRUGOBaAfmCByXtVPoT2/file1.txt
,但您的规则仅定义 匹配/users/{userId}/{fileName}
。由于您只允许在 /users/...
中进行访问,并且您尝试使用的路径不在 /users
中,因此访问会被规则拒绝。
关于firebase-authentication - Firebase 存储安全规则 Playground "Simulated read denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70409878/