firebase - 在使用 firestore 权限的 native 应用程序(通过 Expo)中 - request.auth 始终为 null

标签 firebase react-native firebase-authentication google-cloud-firestore

这是我的代码:

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 [Connection]: WebChannel received error: {"code":403,"message":"Missing or insufficient permissions.","status":"PERMISSION_DENIED"}

最佳答案

当我在 Expo 上遇到最新的 Firebase JS SDK 问题时,我降级到 Firebase SDK 4.6.2。

此外,您必须这样做才能使一切正常工作:

复制 https://gist.githubusercontent.com/mikelehen/444950a35019208f3aaf18d37ab4937c/raw/85ac4cb3108d92163cb8f04fbdddcc88d4081aab/index.js

在您的 node_modules/@firebase/webchannel-wrapper/dist/index.js
没有这个,你将不会从你的收藏中得到任何东西。

希望这可以帮助。

关于firebase - 在使用 firestore 权限的 native 应用程序(通过 Expo)中 - request.auth 始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47859246/

相关文章:

reactjs - 如何在 React Native 中下载图像期间避免 "Excessive number of pending callbacks: 501"错误?

node.js - 如何使用 next.js 进行 firebase 身份验证

android - Firebase 身份验证不成功android

swift - 在 firestore 中返回带有查询的文档

java - react native - 错误 : method does not override or implement a method from a supertype

AngularFire2 4.0.0 : Login with Email & Password

reactjs - 如何在 react-native 中使用 svg 图像作为背景图像?

ios - 使用 Firebase Auth 进行身份验证时注销 Facebook 用户

android - 如何开始使用 App-Tracking?

java - for 循环返回空并且单击时没有显示任何内容