Cloud Firestore:缺少权限或权限不足 [英] Cloud Firestore: Missing or insufficient permissions

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

问题描述

(在Android上)我正在获取:

I am getting (on Android):

com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED:权限丢失或不足

com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions

使用以下安全规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

我的应用似乎已使用FirebaseAuth进行了正确的身份验证,因为mFirebaseAuth.getCurrentUser().getUid()返回正确的用户ID.

My app seems to be properly authenticated using FirebaseAuth, as the mFirebaseAuth.getCurrentUser().getUid() returns the proper user ID.

我在做错什么吗?

推荐答案

只是想说我设法通过降级到4.6.2来解决此问题.我在这篇文章

just want to say that I managed to fix the issue by downgrading to 4.6.2. I have more details in this post

自从我升级本机以来,这种情况就一直在我身上发生,我一生无法解决问题.我已经对其进行调试,并且在请求时我的用户已经通过身份验证,我通过运行以下命令进行了检查,并且其中有一个uid

Pre-edit: This is happening to me ever since I upgraded react native and I cannot for the life of me figure out the problem. I've debugged it and my user is definitely authenticated at the time of the request, I checked this by running the below and I have a uid in there

firebase.auth().currentUser

因此,我接下来要做的是检查实际请求中的会话以了解发生了什么.我在我的应用程序的入口处添加了一段代码

So the next thing I wanted to do was check the session in the actual request to see what was happening. I added a piece of code to the entry point of my react app

XMLHttpRequest = GLOBAL.originalXMLHttpRequest ?
GLOBAL.originalXMLHttpRequest :
GLOBAL.XMLHttpRequest

,当我运行此代码时,它再次神奇地工作.这是通过浏览器委派请求,尽管可能不是真正的测试.

and when I run this code it magically works again. This is delegating requests through the browser though so probably not a true test.

因此,我随后启动了Charles,并将对我的新react-native版本的请求与我的旧的[正在工作] react-native版本的请求进行了比较.这些请求对我来说看起来是一样的(除了不同的sessionId),所以我不知道.令人沮丧的是缺少通过Firestore控制台的调试工具.

So then I started up Charles and compared the requests for my new react-native build with my old [working] react-native build. The requests look the same to me though (apart from a different sessionId) so I have no idea. The frustrating thing is the lack of debug tools through the firestore console.

我的直觉是说某些auth标头已过期/已缓存,并且不是firestore.此时,我的头撞在桌子上

My gut is to say some of the auth headers are expired/cached and that it's not firestore. Banging my head against a table at this point

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

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