0

I have been a while without touching Firebase and just got back to it for a new iOS project. I am using Xcode 10.0 and iOS 12.0.1.

Here is an issue I have. For testing purpose I have chosen these DB rules:

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

And my swift code for writing data to the Firebase DB is as follow:

// reference is of type DatabaseReference, dataDico is of type [String : Any]

reference.setValue(dataDico) {
    (error, ref) -> Void in
    if error == nil {
        print("All was OK !!!")
        return
    }

    if error!.localizedDescription == "Permission denied" {
        print("Permission has been denied !!")
        return
    }

    print("We were not able to do the job (for some reason) !\n\(error)")
}

Strangely enough I always get the message: Permission has been denied !!

Anyone can point out what I am missing here?

Jacob Ahlberg
  • 2,352
  • 6
  • 22
  • 44
Michel
  • 10,303
  • 17
  • 82
  • 179
  • You are using FireStore DB or RealTime DB? – Sohil R. Memon Oct 19 '18 at 02:30
  • I am using Cloud Firestore. – Michel Oct 19 '18 at 02:36
  • try this `service cloud.firestore { match /** { allow read, write; } }` – Sohil R. Memon Oct 19 '18 at 02:46
  • I just tried. But it does as before (same "Permission .. denied" message) and (of course) no data is written. Beside the rules are no longer flagged as ultra-insecure as before. – Michel Oct 19 '18 at 03:02
  • The security rules you're showing apply to Cloud Firestore, while the code you're showing is accessing the Realtime Database. While both databases are part of Firebase, they're completely separate, and the security for one don't apply to the other. To fix the error, you will have to set the rules for the Realtime Database. For a walkthrough of how to do that, see https://stackoverflow.com/a/52129163 – Frank van Puffelen Oct 19 '18 at 04:02
  • Yes, indeed I was mixing up the two and that was the issue. Now it is working. – Michel Oct 24 '18 at 09:00

0 Answers0