【问题标题】:Firestore Insufficient PermissionsFirestore 权限不足
【发布时间】:2018-12-07 00:05:24
【问题描述】:

我不断收到此错误:

Adding Post Error: Missing or insufficient permissions.

这些是我当前的权限,它允许任何人做任何事情(这并不理想,但我只是在测试)。

service cloud.firestore {
  match /databases/{database}/documents {
    match /Posts {
        allow read, write;
    }
  }
}

我要运行的代码是:

func addPost (postID: String, date: NSDate, link: String, profileID: String, text: String) {
    let db = Firestore.firestore()
    let settings = db.settings
    settings.areTimestampsInSnapshotsEnabled = true
    db.settings = settings
    db.collection("Posts").document(postID).setData(["Date": date, "Link": link, "ProfileID": profileID, "Text": text]) { (error) in
        if (error != nil) {
            print ("Adding Post Error: " + error!.localizedDescription)
        } else {
            print("Post added sucessfully")
        }
    }

}

为什么我会收到此错误消息?截至 2018 年 6 月 27 日,我正在运行最新版本的 FirebaseFirestore

【问题讨论】:

  • 尝试服务 cloud.firestore { match /databases/{database}/documents {允许读取,写入;匹配 /Posts { 允许读、写;

标签: swift firebase google-cloud-firestore firebase-security


【解决方案1】:

我很确定您需要指定允许用户访问集合中的文档,如documentation on basic read/write rules 所示:

service cloud.firestore {
  match /databases/{database}/documents {
    match /Posts/{post} {
        allow read, write;
    }
  }
}

上面的区别是{post}match /Posts/{post}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-25
    • 2019-02-26
    • 2018-09-12
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 2020-09-01
    • 2019-01-06
    相关资源
    最近更新 更多