googlearchive / generator-angularfire

Yeoman generator for AngularFire: Angular + Firebase apps
191 stars 52 forks source link

Redirect not working correctly on secured routes #40

Closed maxbortone closed 9 years ago

maxbortone commented 9 years ago

When securing a route using the whenAuthenticated method, for example the chat route in the sample app, the redirect isn't triggered immediately after clicking the link in the navigation, while I'm not logged in. However, the redirect works if I go to the chat route using the browser address bar. I was able to solve this problem by replacing the code in my app with the appropriate modules from the angularfire-seed. In particular, I've replaced routes.js, simpleLogin.js and added changeEmail.js.

jabas06 commented 9 years ago

I have the same issue. The problem is in the routeChangeError event

// some of our routes may reject resolve promises with the special {authRequired: true} error
// this redirects to the login page whenever that is encountered
$rootScope.$on('$routeChangeError', function(e, next, prev, err) {
    if( angular.isObject(err) && err.authRequired ) {
          $location.path(loginRedirectPath);
   }
});

When routeChangeError is triggered, the err argument is not an object. Actually it is a string with value "AUTH_REQUIRED"

maxbortone commented 9 years ago

I've swapped ngRoute for ui-router and that issues isn't a problem anymore: the error on $stateChangeError is an object with a property authRequired set to true, if the particular state I'm navigating to is secured in routes.js. I'm still testing my solution to the issue to see if it is working correctly.

katowulf commented 9 years ago

Thanks, gents. Fixed for the 1.0.0 release.