Angularfire null auth变量

时间:2014-08-15 14:25:39

标签: angularjs firebase ionic-framework firebase-security firebasesimplelogin

我对firebase有一个奇怪的问题。 auth变量为null。我使用简单登录来记录用户:

$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'
            });
        });
    };

将数据保存到firebase后,一切都很好。我无法再访问数据了。我尝试获取数据时出现此错误

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"
              }
            }
          }
        }
    }
} 

有关如何解决这个问题的想法吗?

1 个答案:

答案 0 :(得分:1)

我通过将simpleLogin服务注入到我的所有其他控制器中来实现这一点。

// simple login service
app.factory("simpleLogin", ["$firebaseSimpleLogin",
    function($firebaseSimpleLogin) {
        return $firebaseSimpleLogin(dataBase);
    }
]);