[SECARSP-110][SECARSP-112] Registration/login/logout components are implemented
[platform/core/security/suspicious-activity-monitor.git] / dashboard / src / app / @core / core.module.ts
1 import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
2 import { CommonModule } from '@angular/common';
3 import { NbAuthModule, NbEmailPassAuthProvider } from '@nebular/auth';
4
5 import { throwIfAlreadyLoaded } from './module-import-guard';
6 import { DataModule } from './data/data.module';
7 import { AnalyticsService } from './utils/analytics.service';
8 import { SERVER_URL } from '../../../config';
9 import { AuthInterceptor } from './auth/auth-interceptor';
10 import { HTTP_INTERCEPTORS } from '@angular/common/http';
11
12 const NB_CORE_PROVIDERS = [
13   ...DataModule.forRoot().providers,
14   ...NbAuthModule.forRoot({
15     providers: {
16       email: {
17         service: NbEmailPassAuthProvider,
18         config: {
19           token: {
20             key: 'id_token',
21           },
22           baseEndpoint: SERVER_URL,
23           login: {
24             endpoint: '/auth/login',
25             redirect: {
26               success: '/home/dashboard',
27             },
28           },
29           register: {
30             endpoint: '/auth/register',
31             redirect: {
32               success: '/auth/login',
33             },
34           },
35         },
36       },
37     },
38     forms: {
39       register: {
40         terms: false,
41       },
42       validation: {
43         password: {
44           minLength: 6,
45           maxLength: 100,
46         },
47         fullName: {
48           required: true,
49         },
50       },
51     },
52   }).providers,
53   AnalyticsService,
54 ];
55
56 @NgModule({
57   imports: [
58     CommonModule,
59   ],
60   exports: [
61     NbAuthModule,
62   ],
63   declarations: [],
64   providers: [
65     {
66       provide: HTTP_INTERCEPTORS,
67       useClass: AuthInterceptor,
68       multi: true,
69     },
70   ],
71 })
72 export class CoreModule {
73   constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
74     throwIfAlreadyLoaded(parentModule, 'CoreModule');
75   }
76
77   static forRoot(): ModuleWithProviders {
78     return <ModuleWithProviders>{
79       ngModule: CoreModule,
80       providers: [
81         ...NB_CORE_PROVIDERS,
82       ],
83     };
84   }
85 }