Reputation: 459
Using Firestore, I'm trying to add a new collection and document. I keep getting "Missing or insufficient permissions". What's the problem? What permission do I still need?
struct FirestoreReferenceManager {
static let db = Firestore.firestore()
static let root = db.collection("dev").document("dev")
}
ViewController
@IBAction func handleRegistration(_ sender: Any) {
FirestoreReferenceManager.root.collection("cities").document("LA").setData(["name": "Los Angeles", "state": "CA"]) { (err) in
if let err = err {
print("Error writing document:", err.localizedDescription)
}
}
}
Upvotes: 1
Views: 125
Reputation: 2128
Please perform this step :
1) Open console and open your project
2) Open database -> Cloud Firestore
3) Click on RULES
4) Make allow read, write: if true instead of if false
service cloud.firestore { match /databases/{database}/documents {
match /<some_path>/ {
allow read, write: if true;
} } }
Make allow read, write: if request.auth.uid != null instead of if false
service cloud.firestore { match /databases/{database}/documents {
match /<some_path>/ {
allow read, write: if request.auth.uid != null;
} } }
This will set permission for read and write data on firestore.
Upvotes: 0
Reputation: 2368
Try,
go to Database
-> Rules -> Change allow read, write:
if false to if request.auth != null
or
go to Database
-> Rules -> Change allow read, write:
if false to if true
It turns off security for the database!
It is not recommended solution for production environment but you can use for only testing purposes
More you can find here: https://firebase.google.com/docs/firestore/security/rules-conditions
Upvotes: 4