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

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

问题描述

我一直在使用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 lib正在进行的调用根本没有标题。

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;
    }
  }
}

我试图调用的电话make(并且文档中肯定存在数据)如下:

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似乎解决了这个问题。我不确定确切的根本原因,但auth标头发送方式的行为似乎已经改变了(所以可能存在某些东西?)。如果我有时间进一步调查,我会更新我的答案。如果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.

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

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