auth.module.ts 1012 B

123456789101112131415161718192021222324252627282930313233
  1. import type { JwtConfig } from '@/types';
  2. import { Module } from '@nestjs/common';
  3. import { ConfigService } from '@nestjs/config';
  4. import { JwtModule } from '@nestjs/jwt';
  5. import { UsersModule } from '../users/users.module';
  6. import { AuthController } from './auth.controller';
  7. import { AuthService } from './auth.service';
  8. import { JwtStrategy } from './jwt.strategy';
  9. import { LocalStrategy } from './local.strategy';
  10. import { JwtRefreshStrategy } from './refresh-token.strategy';
  11. @Module({
  12. controllers: [AuthController],
  13. exports: [AuthService],
  14. imports: [
  15. UsersModule,
  16. JwtModule.registerAsync({
  17. global: true,
  18. inject: [ConfigService],
  19. useFactory: async (configService: ConfigService) => {
  20. const { expiresIn, secret } = configService.get<JwtConfig>('jwt');
  21. return {
  22. secret,
  23. signOptions: { expiresIn },
  24. };
  25. },
  26. }),
  27. ],
  28. providers: [AuthService, JwtStrategy, JwtRefreshStrategy, LocalStrategy],
  29. })
  30. export class AuthModule {}