keyshade
keyshade copied to clipboard
API: `JWT_SECRET` not working properly.
Describe the bug
We have migrated to using zod for validating our env schema (refer #200). Recently, I have encountered an error where we can't log in due to JWT_SECRET
not being fetched properly. Rest assured, I have double-checked on the paths and environmental variables to ensure that everything else is working.
Note that, if I try console.log(process.env.JWT_SECRET)
anywhere else in the code, it outputs the expected value without fault. The error seems to be occurring in the JwtModule
initialization in auth.module.ts
.
Also note, if I use process.env.JWT_SECRET ?? 'some-value'
in the JwtModule
registration code, it seems to work fine.
To Reproduce Steps to reproduce the behavior:
- Run the API.
- Use the
/api/auth/send-otp
endpoint to send an OTP to your email. - Copy the OTP and use
/api/auth/validate-otp
to validate your code. - Encounter the
500 Internal Server Error
error in your response.
Expected behavior
- Authentication should have flowed smoothly.
- The user object should be reutrned as a response.
- The JWT bearer token should be sent as a cookie.
Screenshots
-
Response error:
-
Console log
Additional context
You can find the files in here: