xpeditis2.0/apps/backend/src/application/auth/auth.module.ts
David-Henri ARNAUD dc1c881842 feature phase 2
2025-10-09 15:03:53 +02:00

53 lines
1.6 KiB
TypeScript

import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthService } from './auth.service';
import { JwtStrategy } from './jwt.strategy';
import { AuthController } from '../controllers/auth.controller';
// Import domain and infrastructure dependencies
import { USER_REPOSITORY } from '../../domain/ports/out/user.repository';
import { TypeOrmUserRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-user.repository';
/**
* Authentication Module
*
* Wires together the authentication system:
* - JWT configuration with access/refresh tokens
* - Passport JWT strategy
* - Auth service and controller
* - User repository for database access
*
* This module should be imported in AppModule.
*/
@Module({
imports: [
// Passport configuration
PassportModule.register({ defaultStrategy: 'jwt' }),
// JWT configuration with async factory
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
secret: configService.get<string>('JWT_SECRET'),
signOptions: {
expiresIn: configService.get<string>('JWT_ACCESS_EXPIRATION', '15m'),
},
}),
}),
],
controllers: [AuthController],
providers: [
AuthService,
JwtStrategy,
{
provide: USER_REPOSITORY,
useClass: TypeOrmUserRepository,
},
],
exports: [AuthService, JwtStrategy, PassportModule],
})
export class AuthModule {}