File size: 1,391 Bytes
53f00a1
13dd365
 
9a12f24
13dd365
 
9a12f24
5ec5d67
85b81c4
8b6297d
53f00a1
9a12f24
 
5ec5d67
 
 
 
8283e17
5ec5d67
 
9a12f24
 
 
 
 
 
 
85b81c4
 
 
 
8b6297d
 
9a12f24
53f00a1
9a12f24
53f00a1
5ec5d67
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
import { Module } from '@nestjs/common';
import { AuthenticationService } from './authentication.service.js';
import { UserModule } from '../user/user.module.js';
import { JwtModule } from '@nestjs/jwt';
import { AuthenticationController } from './authentication.controller.js';
import { AuthenticationGuard } from './authentication.guard.js';
import { APP_GUARD } from '@nestjs/core';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RolesGuard } from './authorization/roles.guard.js';
import { ValidateService } from '../../validate/validate.service.js';
@Module({
  imports: [
    UserModule,
    JwtModule.registerAsync({
      imports: [ConfigModule], // Nhập ConfigModule để sử dụng ConfigService
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('JWT_KEY'), // Lấy giá trị từ biến môi trường
        signOptions: { expiresIn: '7d' }, // Thời gian hết hạn token
      }),
      inject: [ConfigService], // Inject ConfigService vào factory
    }),
  ],
  providers: [
    AuthenticationService,
    {
      provide: APP_GUARD,
      useClass: AuthenticationGuard,
    },
    {
      provide: APP_GUARD,
      useClass: RolesGuard,
    },
    ValidateService
  ],
  controllers: [AuthenticationController],
  exports: [AuthenticationService],
})
export class AuthenticationModule {}