0

I'm having a weird problem with firebase. The auth variable is null. I use the simple login to log the users in:

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

Everything is fine up to here, after saving the data to the firebase. I'm no longer able to access the data. I get this error when I try to get the data

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) 

And this one:

FIREBASE WARNING: on() or once() for /google:112071360789342135505/settings failed: Error: permission_denied: Client doesn't have permission to access the desired data.  

And this is my security rules:

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

Any thoughts on how to fix this?

3
  • Maybe you are running your app in file server not http server. Commented Aug 16, 2014 at 3:28
  • I'm running it on a http server. Commented Aug 16, 2014 at 12:56
  • Where is the auth variable set? Nowhere in your example. For it to exist on $scope, it has to be set somewhere. What version of AngularFire? Commented Aug 18, 2014 at 22:18

1 Answer 1

1

I got this working by injecting the simpleLogin service into my all other controllers.

// simple login service
app.factory("simpleLogin", ["$firebaseSimpleLogin",
    function($firebaseSimpleLogin) {
        return $firebaseSimpleLogin(dataBase);
    }
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.