forked from auth0/angular2-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
50 lines (46 loc) · 1.44 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { NgModule, ModuleWithProviders, Optional, SkipSelf, Provider } from '@angular/core';
import { JwtInterceptor } from './src/jwt.interceptor';
import { JwtHelperService } from './src/jwthelper.service';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { JWT_OPTIONS } from './src/jwtoptions.token';
export * from './src/jwt.interceptor';
export * from './src/jwthelper.service';
export * from './src/jwtoptions.token';
export interface JwtModuleOptions {
jwtOptionsProvider?: Provider;
config?: {
tokenGetter?: () => string | null | Promise<string | null>;
headerName?: string;
authScheme?: string;
whitelistedDomains?: Array<string | RegExp>;
blacklistedRoutes?: Array<string | RegExp>;
throwNoTokenError?: boolean;
skipWhenExpired?: boolean;
};
}
@NgModule()
export class JwtModule {
constructor(@Optional() @SkipSelf() parentModule: JwtModule) {
if (parentModule) {
throw new Error('JwtModule is already loaded. It should only be imported in your application\'s main module.');
}
}
static forRoot(options: JwtModuleOptions): ModuleWithProviders {
return {
ngModule: JwtModule,
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: JwtInterceptor,
multi: true
},
options.jwtOptionsProvider ||
{
provide: JWT_OPTIONS,
useValue: options.config
},
JwtHelperService
]
};
}
}