@MrCroissant

Как передать на firebase uid авторизации?

Делаю проект на ангуляре с базой на firebase. И у меня возникла проблема с ролями и uid.
Я сделал страницу авторизации которая работает и после авторизации я попадаю на страницу на которой должны выводиться статьи из firebase. Но мне постоянно пишет в консоли :
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)

И я не могу нечего сделать. Роли на firebase такие:
{
  "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

Все прекрасно работает, но нужно что бы все было через uid.

Вот моя авторизация:
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)
        })
    });

  }
]);

Буду невероятно благодарен вашей помощи.
  • Вопрос задан
  • 909 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы