Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning in the console about permission denied (Firebase)

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

like image 599
wm.p1us Avatar asked Mar 03 '17 16:03

wm.p1us


1 Answers

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.

like image 121
Gabriele Mariotti Avatar answered Nov 05 '22 05:11

Gabriele Mariotti