2

Show of weird behavior

This happens everytime I hit the login button.

First login: callback shows 2 logins

First logout

Second login: callback shows 4 logins

Second logout

Third login: callback now shows 5 logins in row

etc.

This is my login function:

$scope.userLogin = function(user){
        $scope.userLoginEmail = user.email;
        $scope.userLoginPassword = user.password;

        $scope.authUser().login('password', {
            email: $scope.userLoginEmail,
            password: $scope.userLoginPassword
        });
        $scope.loginModalHide();
        user.email = '';
        user.password = '';
    };

My question is simple. Why is this happening? Sometimes even if I hit logout, login is called automatically.

6
  • 1
    The code sample you've provided above does not reproduce the error you've described. Please provide a short code sample that reproduces the error. Commented Jul 14, 2014 at 14:59
  • @Kato So there is my AuthCtrl and Factory: jsfiddle.net/D9v7j Commented Jul 14, 2014 at 17:15
  • That code still doesn't run or produce the condition you've described :( Commented Jul 14, 2014 at 17:30
  • @Kato I can't run whole code because I use Appgyver Steroids and code just don't run in jsfiddle. I provided whole Auth controller and I think there is everything about login function. I've updated it and provide login modal. The point is, function is just copied from Firebase page. Commented Jul 14, 2014 at 17:57
  • @Kato There is whole app on Github: github.com/Jirka1111/smoneybox/tree/master/www Commented Jul 14, 2014 at 18:09

1 Answer 1

2

From a looking at your AuthCtrl it seems that you're using FirebaseSimpleLogin without the AngularFire bindings. You'll run into issues with the $digest loop this way. One of the benefits of using AngularFire is that it places nice with $digest loop so we don't have to worry about applying scope or setting timeouts.

AngularFire provides a $firebaseSimpleLogin binding. When a user logs in and out an event is fired off on $rootScope.

app.controller('AuthCtrl', function($scope, $rootScope, $firebaseSimpleLogin) {
  var simpleLogin = $firebaseSimpleLogin(new Firebase('<your-firebase>'));

  $scope.user = {
    email: '',
    password: ''
  };

  $scope.login = function() {
    simpleLogin.$login('password', {
      email: user.email,
      password: user.password
    });
  };

  $rootScope.$on('$firebaseSimpleLogin:login', function(e, user) {
    // handler post login event
  });

  $rootScope.$on('$firebaseSimpleLogin:logout', function(e, user) {
    // handler post logout event
  });

});

I usually encapsulate the $firebaseSimpleLogin binding within a factory. You can check out an demo example on Plunker here:

Plunker Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. I will try implement this and learn Angular better. Still have issues with understanding factories etc. Thanks again! By the way, great simple graphic on your Plunker demo ;)

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.