It's difficult to say without seeing the rest of the application, but there is one error: in the first code sample, you're attaching another event listener every time $scope.logout
is called--e.g., if you call it twice, the next time the event fires it'll alert twice. Click it again, and the next time the event fires, you'll get three alerts. You should move the registration of the event listener outside of the function call:
// put this anywhere that's only called once
app.run(function($rootScope) {
$rootScope.$on("$firebaseSimpleLogin:logout", ...);
});
// elsewhere
$scope.logout = function() {
$rootScope.auth.$logout();
};
// You could also unregister the function when you're done with it instead
app.controller("AuthController", function($scope, $rootScope) {
var unregListener = $rootScope.$on("$firebaseSimpleLogin:logout", ...);
$scope.$on("$destroy", unregListener);
$scope.logout = function() { ... };
});