Here is my code:
var handler:FIRDatabaseHandle!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.handler = self.ref.observe(.value, with: {[weak self] (snapshot) in
var _tasks = Array<Task>()
for item in snapshot.children {
let task = Task(snapshot: item as! FIRDataSnapshot)
_tasks.append(task)
}
self?.tasks = _tasks
self?.tableView.reloadData()
})
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.ref.removeAllObservers()
}
So when I leave this controller (actually I sign out) I see next warning in the console:
[Firebase/Database][I-RDB04822] Listener at /users/ovLWTmGIPFaF6DaLzrPBBr13/tasks failed: permission_denied
It happens because you are not authorized to the Database.
You have a listener attached to a location where it doesn't have permission.
Check the Rules Tab in the Realtime database
If it's
{
"rules": {
".read": "auth != null",
".write":"auth != null"
}
}
This means that only authorized user's can write and read the Data.
Changing to
{
"rules": {
".read": true,
".write":true
}
}
Allows anyone to read/write the Database.
Of course it is (usually) not a valid rule for a production environment but it is useful to check your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With