【发布时间】:2018-05-31 06:02:42
【问题描述】:
这是我的代码:
firebase.auth().onAuthStateChanged((user) => {
if (user) {
console.log("We are authenticated now!");
firebase.firestore().collection("users")
.doc(firebase.auth().currentUser.uid).set({ name: "new name" });
} else {
loginWithFacebook();
}
});
还有,这是我的许可规则:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null;
}
}
}
似乎无论如何,request.auth 总是为空。 我得到的错误:
Firestore (4.8.0) 2017-12-20T04:18:27.321Z [连接]:WebChannel 收到错误:{"code":403,"message":"缺失或不足 权限。","status":"PERMISSION_DENIED"}
【问题讨论】:
-
你是如何测试这个的?您无法打印安全规则的值,那么您使用什么来验证它始终为空?您如何验证您正在连接到正确的端点?您在这里所拥有的一切看起来都不是问题,因此缺少一些东西。
-
@Kato - 简单:使用
allow read, write: if true;我可以读写数据库,而使用allow read, write: if request.auth != null;我得到权限错误,这意味着 request.auth 为空。 -
这并不意味着 request.auth 为空。可能只是您在协调身份验证之前尝试连接。
-
我遇到了完全相同的问题。我正在尝试在验证后立即编写文档。我通过将规则设置为 'request.auth.userId != null' 验证了 id 是否为空,但它仍然失败。我还没有弄清楚什么是错的:(
标签: firebase react-native firebase-authentication google-cloud-firestore