【发布时间】:2018-02-12 07:07:19
【问题描述】:
我已经在 Firebase 中处理了两天的授权,但我无法让它工作。大量阅读文档和 stackoverflow 中的内容,但仍然不明白。这就是我的规则的样子...
{
"rules": {
".read": false,
".write": false,
"notes": {
".read": "auth != null",
".write": "auth != null",
".indexOn": "uid"
}
}
}
我的数据看起来像这样......
user-notes-very-upper-root
|_notes
|_-ugly_id_for_this_record
| |--date: "Sat Sep 02 2017"
| |--note: "new note from me"
| |__uid: "firebase_ugly_id"
|_-ugly_id_for_this_record
就像我之前说的,我会写但我不会读。我正在为此使用 angularjs 1.6.6。我在.run 部分有一个firebase onAuthStateChange 来监听身份验证更改,并且我可以在应用程序周围移动用户obj。我的角度代码看起来像这样......
angular.module('userNotes').run(function($rootScope, $window) {
$rootScope.currentUser = null;
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
$rootScope.currentUser = user.uid;
console.log('User logged in from Run: ', user);
} else {
$rootScope.currentUser = null;
console.warn('User logged out from Run: ', user);
$window.location.href = '#!/';
}
});
});
如果我将rules 节点之后的.read 和.write 规则更改为true,我可以毫无问题地读取数据,但我不想那样做。我只想读取经过身份验证的用户的数据。
我如何调整规则以使经过身份验证的用户能够读取和写入数据。
2017 年 9 月 4 日更新
我把规则改成……
{
"rules": {
"notes": {
".read": "auth != null",
".write": "auth != null",
".indexOn": "uid"
}
}
}
这些规则不能解决问题。我会写但不会读。这是控制台中的错误...
Possibly unhandled rejection: {"data":{"error":"Permission denied"},"status":401
【问题讨论】:
标签: angularjs authentication firebase rules