Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client doesn't have permission to access the desired data in Firebase

I have a page that is calling addCheckin() method which is inside a controller. In the controller, I am trying to create a reference as follows:

var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins"); 

$scope.whichuser and $scope.whichmeeting are the $routeParams that I am passing from another route. Here's my checkin controller-

myApp.controller("CheckinsController",     ['$scope','$rootScope','$firebaseArray','$routeParams','$firebaseObject',     function($scope,$rootScope,$firebaseArray,$routeParams,$firebaseObject){          $scope.whichuser = $routeParams.uid;         $scope.whichmeeting = $routeParams.mid;          var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");          $scope.addCheckin = function(){             var checkinInfo = $firebaseArray(ref);             var data={                 firstname:$scope.firstname,                 lastname:$scope.lastname,                 email:$scope.email,                 date:firebase.database.ServerValue.TIMESTAMP             }              checkinInfo.$add(data);         }  }]);/*controller*/ 

There are two errors that I am getting here-

Error 1:

Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings: Client doesn't have permission to access the desired data.

Error 2:

Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings/-KT5tqMYKXsFssmcRLm6/checkins: Client doesn't have permission to access the desired data.

And this is what I am tring to achieve-

enter image description here

like image 328
Aakash Thakur Avatar asked Oct 04 '16 10:10

Aakash Thakur


People also ask

How do I access my Firebase database via HTTP REST API?

You can use any Firebase Realtime Database URL as a REST endpoint. All you need to do is append . json to the end of the URL and send a request from your favorite HTTPS client. HTTPS is required.

What are the restrictions in Firebase?

Firebase Security Rules work by matching a pattern against database paths, and then applying custom conditions to allow access to data at those paths. All Rules across Firebase products have a path-matching component and a conditional statement allowing read or write access.


2 Answers

Go to Firebase console of your app

Select Database From Side Menu --> Select Rule From tabs above --> Update your rule like this

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

hope it solve your problem . thanks :)

like image 61
Ujjwal kaushik Avatar answered Oct 06 '22 04:10

Ujjwal kaushik


Firebase project by default starts with Firestore as database.

This issue can happen if the application uses "Firebase Realtime Database" and permission for it are not configured. Read and write permission for Firebase Realtime Database should be explicitly granted.

To do so, in Firebase console, Database > Pick "Realtime Database" instead of "Firestore Beta" from the dropdown beside Database > Rules > Set

{ /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */ "rules": { ".read": true, ".write": true } } 

Hope that help!

like image 32
kundan Avatar answered Oct 06 '22 06:10

kundan