1
- // import angular from 'angular';
2
- // // import ngAnimate from 'angular-animate';
3
- // import ngCookies from 'angular-cookies';
4
- // import ngResource from 'angular-resource';
5
- // import ngSanitize from 'angular-sanitize';
6
- // <%_ if(filters.socketio) { _%>
7
- // import 'angular-socket-io';<% } %>
8
- // <%_ if(filters.ngroute) { _%>
9
- // const ngRoute = require('angular-route');<% } %>
10
- // <%_ if(filters.uirouter) { _%>
11
- // import uiRouter from 'angular-ui-router';<% } %>
12
- // <%_ if(filters.uibootstrap) { _%>
13
- // import uiBootstrap from 'angular-ui-bootstrap';<% } %>
14
- // // import ngMessages from 'angular-messages';
15
- // <%_ if(filters.auth) { _%>
16
- // // import ngValidationMatch from 'angular-validation-match';<% } %>
17
-
18
- // import {routeConfig} from './app.config';
19
-
20
- // <%_ if(filters.auth) { _%>
21
- // import _Auth from '../components/auth/auth.module';
22
- // import account from './account';
23
- // import admin from './admin';<% } %>
24
- // import navbar from '../components/navbar/navbar.component';
25
- // import footer from '../components/footer/footer.component';
26
- // import main from './main/main.component';
27
- // import constants from './app.constants';
28
- // import util from '../components/util/util.module';
29
- // <%_ if(filters.socketio) { _%>
30
- // import socket from '../components/socket/socket.service';<% } %>
31
-
32
- // .config(routeConfig)
33
- // <%_ if(filters.auth) { _%>
34
- // .run(function($rootScope, $location, Auth) {
35
- // 'ngInject';
36
- // // Redirect to login if route requires auth and you're not logged in
37
- // $rootScope.$on('$stateChangeStart', function(event, next) {
38
- // Auth.isLoggedIn(function(loggedIn) {
39
- // if(next.authenticate && !loggedIn) {
40
- // $location.path('/login');
41
- // }
42
- // });
43
- // });
44
- // })<% } %>;
45
-
46
-
47
1
import {
48
2
NgModule ,
49
3
ErrorHandler ,
50
4
Injectable ,
51
5
ApplicationRef ,
6
+ Provider ,
52
7
} from '@angular/core' ;
53
8
import { BrowserModule } from '@angular/platform-browser' ;
54
9
import {
10
+ Http ,
55
11
HttpModule ,
56
12
BaseRequestOptions ,
57
13
RequestOptions ,
@@ -60,15 +16,13 @@ import {
60
16
import {
61
17
removeNgStyles ,
62
18
createNewHosts ,
63
- disposeOldHosts ,
64
19
createInputTransfer ,
65
- restoreInputValues ,
66
20
} from '@angularclass/hmr' ;
67
21
< % _ if ( filters . uirouter ) { - % >
68
22
import { UIRouterModule } from 'ui-router-ng2' ; < % } % >
69
23
< % _ if ( filters . ngroute ) { - % >
70
24
import { RouterModule, Routes } from '@angular/router' ; < % } % >
71
- import { provideAuth } from 'angular2-jwt';
25
+ import { provideAuth , AuthHttp , AuthConfig } from 'angular2-jwt';
72
26
73
27
import { AppComponent } from './app.component';
74
28
import { MainModule } from './main/main.module';
@@ -79,12 +33,19 @@ import { AdminModule } from './admin/admin.module';
79
33
80
34
import constants from './app.constants';
81
35
82
- let providers = [
83
- provideAuth({
84
- // Allow using AuthHttp while not logged in
36
+ export function getAuthHttp(http) {
37
+ return new AuthHttp ( new AuthConfig ( {
85
38
noJwtError : true ,
86
- } )
87
- ];
39
+ globalHeaders : [ { 'Accept' : 'application/json' } ] ,
40
+ tokenGetter : ( ( ) => localStorage . getItem ( 'id_token' ) ) ,
41
+ } ) , http ) ;
42
+ }
43
+
44
+ let providers: Provider[] = [{
45
+ provide : AuthHttp ,
46
+ useFactory : getAuthHttp ,
47
+ deps : [ Http ]
48
+ } ];
88
49
89
50
if(constants.env === 'development') {
90
51
@Injectable ( )
@@ -134,7 +95,7 @@ const appRoutes: Routes = [
134
95
} )
135
96
export class AppModule {
136
97
static parameters = [ ApplicationRef ] ;
137
- constructor ( appRef /* : ApplicationRef*/ ) {
98
+ constructor ( < %= private ( ) % > appRef : ApplicationRef ) {
138
99
this . appRef = appRef ;
139
100
}
140
101
0 commit comments