假设我已将写入规则配置为特定的email
:
{
"rules": {
".read": true,
".write": "auth.email == 'example@example.com'"
}
}
我使用该angularFireAuth
服务登录:
.controller('loginCtrl', ["$scope", "$rootScope", "angularFireAuth", function($scope, $rootScope, angularFireAuth) {
var ref = new Firebase("https://test.firebaseio.com/");
angularFireAuth.initialize(ref, {scope: $scope, name: "user"});
$scope.cred = {};
$scope.signin = function() {
angularFireAuth.login('password', {
email: $scope.cred.user,
password: $scope.cred.password,
rememberMe: true
});
}
}]);
我有一个newCtrl
用于将新项目添加到我的收藏中:
.controller('newCtrl', ["$scope", "$rootScope", "angularFireCollection", function($scope, $rootScope, angularFireCollection) {
var ref = new Firebase("https://test.firebaseio.com/");
$scope.items = angularFireCollection(ref);
}]);
items.add()
当我在我看来调用时:
<input type="text" ng-model="item.name" />
<input type="text" ng-model="item.desc" />
<button ng-click="items.add(item)">submit</button>
Not Authorized
即使在我通过loginCtrl
- 登录后如何在整个应用程序中创建持久身份验证状态?
- 注销后如何在整个应用程序中删除持久身份验证状态?