iOS Firebase/Firestore权限被拒绝 [英] iOS Firebase/Firestore Permission Denied

查看:63
本文介绍了iOS Firebase/Firestore权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题经常被问到,但是提出的解决方案并没有为我解决.

I know this question has been frequently asked, however the solutions proposed did not solve it for me.

我试图建立一个基本的iOS Firestore应用程序,该应用程序在集合中写入一些文档.我遵循标准过程,将GoogleService-Info.plist添加到我的项目中,并在启动时调用FirebaseApp.configure().

I tried to set-up a basic iOS Firestore app which writes some documents inside a collection. I followed the standard procedure, added the GoogleService-Info.plist to my project and I'm calling `FirebaseApp.configure() on launch.

我的Firestore规则如下:

My Firestore rules look like this:

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

现在,一旦我尝试将某些内容保存在集合中,Firebase就会向我返回权限被拒绝"错误.

Now once I try to save something inside a collection Firebase returns me a Permission denied error.

但是,如果我的规则如下:

If however my rules are like so:

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

接受写入.显然,该请求似乎不包含任何身份验证信息,但是我找不到与此有关的任何其他文档.我错过了什么?

The write is accepted. Obviously the request seems to not contain any auth information, but I can't find any additional documentation about this. Did I miss something?

感谢您的帮助!

推荐答案

如果您在应用中使用身份验证,则应该使用

if you are using authentication in your app then you should go with the

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

仅当您在应用中添加了Firebase身份验证时,此方法才有效,但是如果您未添加,则它将返回 PermissionDenied

This will only works if you were added firebase authentication in your app but if you didn't added then it will return PermissionDenied

您也可以使用此方法

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

但是此方法并不安全,任何人都可以一次更改您的整个数据库,而且Firebase不建议您使用此方法.

but this method is not secure anyone can change your whole database at once and also Firebase won't recommend you to use this.

如果您处于开发模式,则可以使用它来创建数据库,但是如果要投入生产,则只需将其更改为任一模式即可.

If you are in developing mode then use this and create your database but if you are going to production, you just need to change it to either

allow read, write: if request.auth.uid != null;

或者如果您的应用程序中没有身份验证.

or if you don't have authentication in your app.

allow read, write: if false;

希望这可以帮助您更好地理解.

Hope this will help you to understand better.

这篇关于iOS Firebase/Firestore权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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