feat: 开发user、auth相关接口,初始化后台管理项目admin
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthController } from './auth.controller';
|
||||
import { JwtStrategy } from './strategies/jwt.strategy';
|
||||
import { User } from '../user/user.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User]),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
// @ts-expect-error - JWT expiresIn accepts string but type definition is strict
|
||||
useFactory: (configService: ConfigService) => {
|
||||
const expiresIn = configService.get<string>(
|
||||
'JWT_EXPIRES_IN',
|
||||
'7d',
|
||||
);
|
||||
const secret = configService.get<string>(
|
||||
'JWT_SECRET',
|
||||
'your-secret-key-change-in-production',
|
||||
);
|
||||
return {
|
||||
secret: secret,
|
||||
signOptions: {
|
||||
expiresIn: expiresIn || '7d', // 默认7天过期
|
||||
},
|
||||
};
|
||||
},
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
controllers: [AuthController],
|
||||
providers: [AuthService, JwtStrategy],
|
||||
exports: [AuthService, JwtModule],
|
||||
})
|
||||
export class AuthModule {}
|
||||
Reference in New Issue
Block a user