【发布时间】:2014-10-09 07:05:40
【问题描述】:
我在使用 Firebase 时遇到了一个奇怪的问题。 auth 变量为空。我使用简单登录来登录用户:
$scope.login = function() {
$scope.auth.$login('google', {
scope: 'https://www.googleapis.com/auth/plus.me'
}).then(function(user) {
// The settings updated
$scope.settings.user = {
name: user.displayName,
email: user.email,
profilePic: user.thirdPartyUserData.picture
};
// save the settings to the database
$firebase(dataBase.child(user.uid)).$set('settings', $scope.settings);
// proceed to the next step
$scope.initialLogin = true;
// set the uid to local storage
permanentStorage.setItem('uid', user.uid);
}, function(error) {
// Ionic alert popup.
var alertPopup = $ionicPopup.alert({
title: 'Something went wrong',
template: error.message,
okType: 'button-assertive'
});
});
};
在将数据保存到火力基地后,一切都很好。我不再能够访问数据。当我尝试获取数据时出现此错误
Error: permission_denied: Client doesn't have permission to access the desired data.
at Error (native)
at dc (http://localhost:8100/js/firebase.js:44:333)
at http://localhost:8100/js/firebase.js:112:200
at http://localhost:8100/js/firebase.js:80:207
at nd.h.gc (http://localhost:8100/js/firebase.js:85:104)
at bd.gc (http://localhost:8100/js/firebase.js:76:364)
at Q.Xd (http://localhost:8100/js/firebase.js:74:280)
at Jc (http://localhost:8100/js/firebase.js:60:234)
at WebSocket.X.onmessage (http://localhost:8100/js/firebase.js:59:111)
还有这个:
FIREBASE WARNING: on() or once() for /google:112071360789342135505/settings failed: Error: permission_denied: Client doesn't have permission to access the desired data.
这是我的安全规则:
{
"rules": {
".write": true,
"$users": {
".read": "$users === auth.uid",
".write": "$users === auth.uid",
"settings" : {
"user" : {
"name": {
".validate": "newData.isString() && newData.val().length <= 2000"
},
"email": {
".validate": "newData.isString() && newData.val().length <= 2000"
}
}
}
}
}
}
关于如何解决此问题的任何想法?
【问题讨论】:
-
也许您在文件服务器而不是 http 服务器中运行您的应用程序。
-
我在 http 服务器上运行它。
-
auth 变量设置在哪里?在你的例子中没有任何地方。为了让它存在于 $scope 上,它必须被设置在某个地方。什么版本的 AngularFire?
标签: angularjs firebase ionic-framework firebase-security firebasesimplelogin