在使用 firestore 权限的本机应用程序(通过 Expo)中 - request.auth 始终为 null [英] In react native app (through Expo) using firestore permissions - request.auth is always null
问题描述
这是我的代码:
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();
}
});
而且,这是我的许可规则:
And, here are my permission rules:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null;
}
}
}
好像不管怎样,request.auth 总是空的.我得到的错误:
It seems like no matter what, request.auth is always null. The error I get:
Firestore (4.8.0) 2017-12-20T04:18:27.321Z [连接]:WebChannel收到错误:{"code":403,"message":"缺失或不足权限.","status":"PERMISSION_DENIED"}
Firestore (4.8.0) 2017-12-20T04:18:27.321Z [Connection]: WebChannel received error: {"code":403,"message":"Missing or insufficient permissions.","status":"PERMISSION_DENIED"}
推荐答案
当我在 Expo 上遇到最新 Firebase JS SDK 的问题时,我降级到 Firebase SDK 4.6.2.
I downgraded to Firebase SDK 4.6.2 when I had this problem with latest Firebase JS SDK on Expo.
此外,您必须这样做才能使一切正常:
Also, you have to do this in order for everything to work:
在你的node_modules/@firebase/webchannel-wrapper/dist/index.js
没有它,您将一无所获.
Without this, you'll get nothing from your collections.
希望这会有所帮助.
这篇关于在使用 firestore 权限的本机应用程序(通过 Expo)中 - request.auth 始终为 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!