config module에서 isGlobal:true로 설정해도 다음과 같은 에러가 나올 때도 있다.
return failure(new error('secretorprivatekey must have a value'));
JwtModule.register 대신 registerAsync를 사용하면 된다.
//auth.module.ts
import { Module } from '@nestjs/common';
import { JwtModule } from "@nestjs/jwt";
import { AuthService } from './auth.service';
import { JwtStrategy } from './jwt.strategy';
import {PassportModule} from "@nestjs/passport"
import { LocalStrategy } from './local.strategy';
import { ConfigService } from '@nestjs/config';
@Module({
imports: [
JwtModule.registerAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
secret: config.get<string>('JWT_SECRET_KEY'),
signOptions: {expiresIn: '86400s'}
})
}),
PassportModule
],
controllers: [],
providers: [
AuthService,
JwtStrategy,
LocalStrategy
],
exports: [
AuthService,
]
})
export class AuthModule {}
'Server > NodeJS & NestJS' 카테고리의 다른 글
ipfs) blob 데이터 이미지 불러오기 (0) | 2022.05.09 |
---|---|
NestJS에서 MySQL ConnectionPool 사용하기 (0) | 2022.04.27 |
NestJS에서 Prisma 사용하기 (0) | 2022.03.15 |
NestJS Morgan logger 사용하기 (0) | 2022.03.11 |
cors 오류 임시로 해결하기 (0) | 2022.03.08 |