feat: token 令牌

This commit is contained in:
ilhamtahir committed 2024-11-17 14:51:09 +08:00
1 parent a2ee53f83a
commit ec0e6867ee
12 files changed
+408 -7

No files matched your search

+19 -3
View File
@@ -1,4 +1,4 @@
import { Global, Module } from '@nestjs/common';
import { Global, Module, OnModuleInit } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TokenController } from './controller/token.controller';
@@ -6,7 +6,9 @@ import { UserService } from './service/user.service';
import { User } from './entity/user.entity';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from './guards/auth.guard';
import { JwtService } from '@nestjs/jwt';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { AuthService } from './service/auth.service';
import { JWT_EXPIRATION, JWT_SECRET } from './constants/jwt';
@Module({
controllers: [TokenController],
@@ -35,6 +37,13 @@ import { JwtService } from '@nestjs/jwt';
inject: [ConfigService],
}),
TypeOrmModule.forFeature([User]),
JwtModule.register({
global: true,
secret: JWT_SECRET,
signOptions: {
expiresIn: JWT_EXPIRATION,
},
}),
],
providers: [
{
@@ -43,8 +52,15 @@ import { JwtService } from '@nestjs/jwt';
},
UserService,
JwtService,
AuthService,
],
exports: [UserService],
})
@Global()
export class CoreModule {}
export class CoreModule implements OnModuleInit {
constructor(private readonly userService: UserService) {}
async onModuleInit() {
await this.userService.createInitialUser();
console.log('Loaded JWT_SECRET:', JWT_SECRET);
}
}