keyshade icon indicating copy to clipboard operation
keyshade copied to clipboard

API: `JWT_SECRET` not working properly.

Open rajdip-b opened this issue 9 months ago • 2 comments

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. image

To Reproduce Steps to reproduce the behavior:

  1. Run the API.
  2. Use the /api/auth/send-otp endpoint to send an OTP to your email.
  3. Copy the OTP and use /api/auth/validate-otp to validate your code.
  4. 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: image

  • Console log image

Additional context

You can find the files in here:

rajdip-b avatar May 13 '24 07:05 rajdip-b