1
1
' use strict'
2
2
3
- angular .module ( ' <%= scriptAppName %>' , [< %= angularModules % > ])
4
- < % if (filters .ngroute ) { % > .config ( ($routeProvider, $locationProvider< % if (filters .auth ) { % > , $httpProvider< % } % > ) ->
5
- $routeProvider
6
- .otherwise
7
- redirectTo : ' /'
3
+ angular .module ' <%= scriptAppName %>' , [< %= angularModules % > ]
4
+ < % if (filters .ngroute ) { % > .config ($routeProvider, $locationProvider< % if (filters .auth ) { % > , $httpProvider< % } % > ) ->
5
+ $routeProvider
6
+ .otherwise
7
+ redirectTo : ' /'
8
8
9
- $locationProvider .html5Mode true < % if (filters .auth ) { % >
10
- $httpProvider .interceptors .push ' authInterceptor' < % } % >
11
- ) < % } % >< % if (filters .uirouter ) { % > .config ( ($stateProvider, $urlRouterProvider, $locationProvider< % if (filters .auth ) { % > , $httpProvider< % } % > ) ->
12
- $urlRouterProvider
13
- .otherwise ( ' /' )
9
+ $locationProvider .html5Mode true < % if (filters .auth ) { % >
10
+ $httpProvider .interceptors .push ' authInterceptor' < % } % >
11
+ < % } % >< % if (filters .uirouter ) { % > .config ($stateProvider, $urlRouterProvider, $locationProvider< % if (filters .auth ) { % > , $httpProvider< % } % > ) ->
12
+ $urlRouterProvider
13
+ .otherwise ' /'
14
14
15
- $locationProvider .html5Mode true < % if (filters .auth ) { % >
16
- $httpProvider .interceptors .push ' authInterceptor' < % } % >
17
- ) < % } % >< % if (filters .auth ) { % >
18
- .factory ( ' authInterceptor' , ($rootScope , $q , $cookieStore , $location ) ->
19
- # Add authorization token to headers
20
- request : (config ) ->
21
- config .headers = config .headers or {}
22
- config .headers .Authorization = ' Bearer ' + $cookieStore .get ( ' token' ) if $cookieStore .get ( ' token' )
23
- config
15
+ $locationProvider .html5Mode true < % if (filters .auth ) { % >
16
+ $httpProvider .interceptors .push ' authInterceptor' < % } % >
17
+ < % } % >< % if (filters .auth ) { % >
18
+ .factory ' authInterceptor' , ($rootScope , $q , $cookieStore , $location ) ->
19
+ # Add authorization token to headers
20
+ request : (config ) ->
21
+ config .headers = config .headers or {}
22
+ config .headers .Authorization = ' Bearer ' + $cookieStore .get ' token' if $cookieStore .get ' token'
23
+ config
24
24
25
- # Intercept 401s and redirect you to login
26
- responseError : (response ) ->
27
- if response .status is 401
28
- $location .path ' /login'
29
- # remove any stale tokens
30
- $cookieStore .remove ' token'
31
- $q .reject response
32
- else
33
- $q .reject response
34
- )
35
- .run (($rootScope , $location , Auth ) ->
36
- # Redirect to login if route requires auth and you're not logged in
37
- $rootScope .$on < % if (filters .ngroute ) { % > ' $routeChangeStart' < % } % >< % if (filters .uirouter ) { % > ' $stateChangeStart' < % } % > , (event , next ) ->
38
- Auth .isLoggedInAsync (loggedIn) ->
39
- $location .path " /login" if next .authenticate and not loggedIn
40
- )< % } % >
25
+ # Intercept 401s and redirect you to login
26
+ responseError : (response ) ->
27
+ if response .status is 401
28
+ $location .path ' /login'
29
+ # remove any stale tokens
30
+ $cookieStore .remove ' token'
31
+
32
+ $q .reject response
33
+
34
+ .run ($rootScope, $location, Auth) ->
35
+ # Redirect to login if route requires auth and you're not logged in
36
+ $rootScope .$on < % if (filters .ngroute ) { % > ' $routeChangeStart' < % } % >< % if (filters .uirouter ) { % > ' $stateChangeStart' < % } % > , (event , next ) ->
37
+ Auth .isLoggedInAsync (loggedIn) ->
38
+ $location .path " /login" if next .authenticate and not loggedIn
39
+ < % } % >
0 commit comments