使用 Expo(React Native)的 Firebase Firestore 缺少或权限不足 [英] Firebase Firestore missing or insufficient permissions using Expo (React Native)

查看:22
本文介绍了使用 Expo(React Native)的 Firebase Firestore 缺少或权限不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在将 FireStore 用于在浏览器中运行良好的项目,但是当我将代码移植到 Expo,在模拟器中的 iOS 11.2 iPhone X 上运行时,它不断引发 错误:缺失或不足权限.

I've been using FireStore for a project that works fine in the browser, but when I port the code to Expo, running on a iOS 11.2 iPhone X in the simulator, it keeps raising Error: Missing or insufficient permissions.

Auth 工作正常,当我在 Firestore 集合对象中检查客户端时,设置了适当的 UID,并在浏览器中测试相同的代码,一切正常(没有权限问题).我想说的是,我 95% 确定问题出在 Firebase lib/react native/expo 组合上,而不是我的代码上.特别是因为似乎在浏览器中调用 Firestore,设置了标头,但是在 Reactotron(来自 Expo)中调试调用时,看起来 Firebase 库进行的调用根本没有标头.

Auth is working fine, and when I check the client in the Firestore collection object, the appropriate UID is set, and testing the same code in the browser, everything works perfectly (no permissions problem). What I'm trying to say is that I'm 95% certain that the issue is with the Firebase lib/react native/expo combination, rather than with my code. Especially since it seems that making a call to Firestore in the browser, there are headers set, but when debugging the call in Reactotron (from Expo), it looks like the call the Firebase lib is making has no headers at all.

我怀疑它会有所作为,但这是我的身份验证规则:

I doubt it makes a difference, but here are my auth rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /UserData/{userID} {
      allow read, write: if request.auth.uid == userID;
    }
    match /MemberData/{userID} {
      allow read: if request.auth.uid == userID;
    }
  }
}

我试图拨打的电话(文档中肯定有数据)如下:

The call I was trying to make (and there is definitely data in the doc) is the following:

profile = (await UserDataCollection.doc(`${idToken.uid}`).get()).data();

我很好奇是否有其他人遇到过这个问题,如果有,是否有任何解决方法可以让 Firestore 正常工作?

I'm curious if anyone else has run into this problem, and if so, are there any workarounds to make Firestore work?

推荐答案

根据之前的评论,降级到 4.6.2 似乎可以解决问题.我不确定确切的根本原因,但发送身份验证标头的行为似乎已经改变(所以可能有什么东西?).如果我有时间进一步调查,我会更新我的答案.很高兴 Firebase 团队中的一个人与我联系以获取我的帐户详细信息,如果他们想在他们这边进行验证.

As per previous comments, downgrading to 4.6.2 seems to fix the issue. I'm not sure the exact root cause but the behaviour of how the auth headers are sent seem to have changed (so potentially something there?). I'll update my answer if I get time to investigate further. Happy for one of the Firebase team to contact me for my account details if they want to verify on their side.

这篇关于使用 Expo(React Native)的 Firebase Firestore 缺少或权限不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆