2025-08-24 02:31:42 +08:00
|
|
|
import { Module, forwardRef } from '@nestjs/common';
|
2025-08-23 13:20:01 +08:00
|
|
|
import { JwtModule } from '@nestjs/jwt';
|
|
|
|
|
import { PassportModule } from '@nestjs/passport';
|
2025-08-24 02:31:42 +08:00
|
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
2025-08-23 13:20:01 +08:00
|
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
2025-08-24 02:31:42 +08:00
|
|
|
import { AuthToken } from './entities/AuthToken';
|
|
|
|
|
import { AuthService } from './services/AuthService';
|
|
|
|
|
import { AuthController } from './controllers/AuthController';
|
|
|
|
|
import { JwtAuthGuard } from './guards/JwtAuthGuard';
|
|
|
|
|
import { RolesGuard } from './guards/RolesGuard';
|
|
|
|
|
|
|
|
|
|
// 导入Admin和Member模块
|
2025-08-23 13:20:01 +08:00
|
|
|
import { AdminModule } from '../admin/admin.module';
|
2025-08-24 02:31:42 +08:00
|
|
|
import { MemberModule } from '../member/MemberModule';
|
2025-08-23 13:20:01 +08:00
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
|
imports: [
|
2025-08-24 02:31:42 +08:00
|
|
|
PassportModule,
|
|
|
|
|
TypeOrmModule.forFeature([AuthToken]),
|
2025-08-23 13:20:01 +08:00
|
|
|
JwtModule.registerAsync({
|
|
|
|
|
imports: [ConfigModule],
|
|
|
|
|
useFactory: async (configService: ConfigService) => ({
|
2025-08-24 02:31:42 +08:00
|
|
|
secret: configService.get('JWT_SECRET', 'change_me'),
|
2025-08-23 13:20:01 +08:00
|
|
|
signOptions: {
|
2025-08-24 02:31:42 +08:00
|
|
|
expiresIn: configService.get('JWT_EXPIRES_IN', '7d'),
|
2025-08-23 13:20:01 +08:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
inject: [ConfigService],
|
|
|
|
|
}),
|
2025-08-24 02:31:42 +08:00
|
|
|
// 导入Admin和Member模块以使用其服务
|
|
|
|
|
forwardRef(() => AdminModule),
|
|
|
|
|
forwardRef(() => MemberModule),
|
2025-08-23 13:20:01 +08:00
|
|
|
],
|
|
|
|
|
providers: [
|
|
|
|
|
AuthService,
|
|
|
|
|
JwtAuthGuard,
|
|
|
|
|
RolesGuard,
|
|
|
|
|
],
|
2025-08-24 02:31:42 +08:00
|
|
|
controllers: [AuthController],
|
2025-08-23 13:20:01 +08:00
|
|
|
exports: [
|
|
|
|
|
AuthService,
|
|
|
|
|
JwtAuthGuard,
|
|
|
|
|
RolesGuard,
|
|
|
|
|
],
|
|
|
|
|
})
|
2025-08-24 02:31:42 +08:00
|
|
|
export class AuthModule {}
|