Android Firebase Database Error: Permission denied

隐身守侯 提交于 2019-12-05 06:42:19

Go to the Rules tab on your Database console. If you have not explicitly granted .read access to your user then permission will be denied.

This link is excellent in the Firebase doc:

https://firebase.google.com/docs/database/security/securing-data

These two notes on that page are of particular interest:

Note: Access is disallowed by default. If no .write or .read rule is specified at or above a path, access will be denied.

Note: Shallower security rules override rules at deeper paths. Child rules can only grant additional privileges to what parent nodes have already declared. They cannot revoke a read or write privilege.

Review the node where permission is being denied and use the Simulator on the Rules tab in order to test your rules for different user security contexts (non-authenticated, authenticated, etc.)

Possible reason could be : you dont have read and write access on your database. For enabling read and write access :

Go to firebase console and enable read and write operations on your database.

Firebase Console -> Database(develop) -> RULES

{
  "rules": {
    ".read": "true",
    ".write": "true"
  }
}
HandyPawan

Do some changes on firebase database.

  1. go to firebase -> Database -> rules

{
  "rules": 
{
    ".read": true,
    ".write": true
  }

}

Do not put you app public if this is not needed. As described on google documentation you can do these rules on your firebase > database > rules

// These rules grant access to a node matching the authenticated
// user's ID from the Firebase auth token
{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

or to let only authenticated users

// These rules require authentication
    {
      "rules": {
        ".read": "auth != null",
        ".write": "auth != null"
      }
    }

Letting an app public let anyone write and read your app... i don't think any app should use this like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!