googlearchive / angularfire-seed

Seed project for AngularFire apps
http://angularfire.com
MIT License
410 stars 191 forks source link

bugfix: whenAuthenticated method now supports chaining #84

Closed robotnoises closed 9 years ago

robotnoises commented 9 years ago

Previously, any routeProvider configured with more than one route would fail if subsequent routes followed a .whenAuthenticated({ ... });

Example:

// This works fine

(function (angular) {

  'use strict';

  angular.module('myApp.task')

  .config(['$routeProvider', function($routeProvider) {

    $routeProvider

    .whenAuthenticated('/foo', {
      controller: 'fooController',
      templateUrl: 'foo.html',
      resolve: {
        user: ['Auth', function (Auth) {
          return Auth.$waitForAuth();
        }]
      }
    })

  }]);

})(angular);

// This fails

(function (angular) {

  'use strict';

  angular.module('myApp.task')

  .config(['$routeProvider', function($routeProvider) {

    $routeProvider

    .whenAuthenticated('/foo', {
      controller: 'fooController',
      templateUrl: 'foo.html',
      resolve: {
        user: ['Auth', function (Auth) {
          return Auth.$waitForAuth();
        }]
      }
    })

    .when('/foo/:id', {
      controller: 'fooController',
      templateUrl: 'foo.html'
      }
    })

  }]);

})(angular);

// This works

(function (angular) {

  'use strict';

  angular.module('myApp.task')

  .config(['$routeProvider', function($routeProvider) {

    $routeProvider

    .when('/foo/:id', {
      controller: 'fooController',
      templateUrl: 'foo.html'
      }
    })

    .whenAuthenticated('/foo', {
      controller: 'fooController',
      templateUrl: 'foo.html',
      resolve: {
        user: ['Auth', function (Auth) {
          return Auth.$waitForAuth();
        }]
      }
    })

  }]);

})(angular);

Let me know what you think!

katowulf commented 9 years ago

Thanks @robotnoises!