Answer the question
In order to leave comments, you need to log in
How to pass authorization uid to firebase?
I'm doing a project in Angular with firebase. And I got a problem with roles and uid.
I made an authorization page that works and after authorization I get to the page on which articles from firebase should be displayed. But it keeps telling me in the console:
Error: permission_denied: Client doesn't have permission to access the desired data.
at Error (native)
at J (https://cdn.firebase.com/js/client/2.2.4/firebase.js:120:36)
at Object.J (https://cdn.firebase.com/js/client/2.2.4/firebase.js:201:378)
at https://cdn.firebase.com/js/client/2.2.4/firebase.js:187:3
at wh.h.Fd (https://cdn.firebase.com/js/client/2.2.4/firebase.js:191:104)
at kh.Fd (https://cdn.firebase.com/js/client/2.2.4/firebase.js:182:364)
at ch.wg (https://cdn.firebase.com/js/client/2.2.4/firebase.js:180:281)
at fh (https://cdn.firebase.com/js/client/2.2.4/firebase.js:174:464)
at WebSocket.va.onmessage (https://cdn.firebase.com/js/client/2.2.4/firebase.js:173:245)
{
"rules": {
"users": {
".read": "auth != null && (root.child('users').child(''+auth.uid).child('isAdmin').val() == true)",
"$uid": {
".read": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)",
".write": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)"
}
},
"files": {
"$uid": {
".read": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)",
".write": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)"
}
},
"stones": {
"$uid": {
".read": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)",
".write": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)"
}
},
"images": {
"$uid": {
".read": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)",
".write": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)"
}
},
"tags": {
"$uid": {
".read": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)",
".write": "auth != null && (auth.uid == $uid || root.child('users').child(''+auth.uid).child('isAdmin').val() == true)"
}
},
"releases": {
".read": true,
".write": true
}
}
}
".read": true,
".write": true
NameApp.controller('authorizationCtrl', ['$scope','$location','$firebaseAuth', function($scope,$location,$firebaseAuth) {
var ref = new Firebase("https://asdasd.firebaseio.com");
var loginObj = $firebaseAuth(ref);
$scope.user = {};
$scope.SignIn = function(e) {
var username = $scope.user.email;
var password = $scope.user.password;
ref.authWithPassword({
email : username,
password : password
},
function authHandler(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
$scope.$apply(function() {
$location.path('/main');
});
}
}
);
}
}]);
angular.module('qweqw.main', ['ngRoute', 'firebase'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/main', {
templateUrl: 'views/main/main.html',
controller: 'mainCtrl'
});
}])
// Inject $firebaseArray instead of $firebase
.controller("mainCtrl", ["$scope", "$firebaseArray",
function($scope, $firebaseArray) {
var ref = new Firebase('https://asdasd.firebaseio.com/users');
var users = $firebaseArray(ref);
users.$loaded()
.then(function(){
angular.forEach(users, function(users) {
// console.log("asdasd" + users);
var q = users;
console.log(q)
})
});
}
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question