codestates / codestates/BanThing
[Error Handling] [nestjs]JwtModule 환경변수 전달 에러 (.env)
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
### 어떤 에러인가요?


isGlobal: true 전역으로 설정했는데 전달이 안되는거 같습니다.
### 에러 핸들링 방법
.env를 읽어오는 작업은 비동기적이다. 이로 인해 JwtModule.register에서 process.env.JWT_SECRET을 참조할 때까지 .env를 다 못 읽어오는 일이 발생했다. 그래서 Error: secretOrPrivateKey must have a value라는 에러가 발생했지만 다행히도 이에 대한 해답을 stackoverflow에서 찾아냈다.
JwtModule에는 registerAsync라는 메소드가 있는데 여기에 ConfigService를 주입해두면 .env를 읽어올 때까지 secret을 등록하는 작업을 유예시킬 수 있다.

### 에러 핸들링을 위해 참고한 레퍼런스 링크
https://stackoverflow.com/questions/67829688/nestjs-configmodule-forroot-isglobal-not-working
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.