Firestore权限错误排查:调用者无权限执行指定操作
Firestore权限错误「调用者无权限执行指定操作」排查与解决
错误原因
你的Firestore安全规则中设置了过期限制:
allow read, write: if request.time < timestamp.date(2024, 6, 1);
当前时间已超过2024年6月1日,所有读写请求均被规则拦截,因此触发「调用者无权限执行指定操作」的错误。
解决办法
临时测试场景(仅限开发调试)
如果只是临时调试需要,可修改规则的过期时间为未来日期,或临时开放全权限(生产环境禁止使用):
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { // 修改为未来过期时间 allow read, write: if request.time < timestamp.date(2025, 6, 1); // 或临时开放全权限(测试用) // allow read, write: if true; } } }
生产环境安全配置
必须根据业务需求配置最小权限规则,以下是常见场景示例:
- 仅允许已认证用户访问:
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if request.auth != null; } } }
- 仅允许用户读写自己的专属文档:
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /users/{userId} { allow read, write: if request.auth.uid == userId; } } }
配置完成后,在Firebase控制台发布规则即可生效。
内容的提问来源于stack exchange,提问作者Ayush Gaikwad
相关产品推荐
相关产品推荐

