在使用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始终为null. 我得到的错误:
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 [Connection]:WebChannel 收到错误:{代码":403,消息":缺少或不足 权限.,"状态:" 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:
复制 https://gist.githubusercontent8.4/a4d /raw/85ac4cb3108d92163cb8f04fbdddcc88d4081aab/index.js
在您的node_modules/@firebase/webchannel-wrapper/dist/index.js
否则,您的收藏夹将一无所获.
Without this, you'll get nothing from your collections.
希望这会有所帮助.
这篇关于在使用Firestore权限(通过Expo)响应本机应用程序中-request.auth始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!