【发布时间】:2016-02-15 18:11:52
【问题描述】:
这是我在 firebase 上的模型:
Texts
-KAa-aU_RjZwM7FLQcWt
id: "5f9fe424-4323-4370-a280-9cb216dc6410"
text: "gregegreg"
-KAa-bZC2ouIRQ54YWWr
id: "5f9fe424-4323-4370-a280-9cb216dc6410"
text: "gregegreg"
这些是我的规则:
"rules": {
"Texts": {
".read": "auth.id === data.child('id').val()",
".write": true
}
}
不幸的是,当我使用 5f9fe424-4323-4370-a280-9cb216dc6410 以外的另一个 UID 登录时,我仍然能够阅读我的所有模型文本
感谢您的任何想法!
身份验证部分适用于 angularJs 和登录密码:
var firebaseObj = new Firebase("https://blinding-heat-xxxx.firebaseio.com");
$scope.authObj = $firebaseAuth(firebaseObj);
$scope.login = function() {
$scope.authData = null;
$scope.error = null;
$scope.authObj.$authWithPassword({
email: $scope.email,
password: $scope.password
}).then(function(authData) {
console.log("Logged with id:", authData.uid);
$scope.loadData();
}).catch(function(error) {
console.error("Auth Failed :", error);
$scope.error = error;
});
};
数据最终像这样加载到网页上:
$scope.loadData = function(){
var ref = new Firebase("https://blinding-heat-xxxx.firebaseio.com");
$scope.Texts = $firebaseArray(ref.child('Texts'));
}
在 HTML 中,angularJs 就在那里:
<div ng-repeat="text in Texts">text.text</div>
真正奇怪的是下面的规则效果很好,例如:
"rules": {
"Texts": {
".read": " auth != null ",
".write": true
}
}
【问题讨论】:
-
Firebase 工程师在这里我注意到了您的最后一次编辑。如果您担心有人入侵您的数据库,我建议您创建一个新数据库,将数据移过来并创建一个新数据库。作为一个额外的优势,您可以选择数据库的名称,而不是获取自动分配的名称。更容易记住。 :-)
标签: angularjs json firebase angularfire