I am trying to read the data that was assigned to a specific user by its uid value,but I get permission denied.
Anyone knows the reason why I get this error?
import UIKit
import Firebase
class ViewController: UIViewController {
// dataChild value == User UID as in console.firebase.google.com
var dataChild = "xd5rwZzUqoRbfMp2rq5pTRB3s1"
var dbRef:FIRDatabaseReference! // reference to Firebase
override func viewDidLoad() {
super.viewDidLoad()
dbRef = FIRDatabase.database().reference().child("Users")
startObservingDB()
}
func startObservingDB() {
dbRef.child(dataChild).observe(.value, with: { (snapshot: FIRDataSnapshot) in
print("The snapshot is \(snapshot.value)") //no longer prints
}, withCancel: { (Error:Any) in
print("Error is \(Error)") //prints Error is Error Domain=com.firebase Code=1 "Permission Denied"
})
} // end of startObservingDB()
}
Firebase Json Tree
{
"Users" : {
"xd5rwZzUqoRbfMp2rq5pTRB3s1" : {
"718565122" : {
"BookingAmount" : "12",
"BookingNumber" : "718565122",
"DateAndTime" : "Mon, 26 Sep 2016 18:30",
"EmailAddress" : "[email protected]",
"FlatNumber" : "10",
"FrequecyAmount" : 48,
Firebase Rules
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}