Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: JWT_SECRET not working properly. #214

Closed
rajdip-b opened this issue May 13, 2024 · 6 comments
Closed

API: JWT_SECRET not working properly. #214

rajdip-b opened this issue May 13, 2024 · 6 comments
Labels
difficulty: 4 help wanted Extra attention is needed priority: low scope: api Everything related to the API type: bug Something isn't working

Comments

@rajdip-b
Copy link
Member

rajdip-b commented May 13, 2024

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 rajdip-b added type: bug Something isn't working help wanted Extra attention is needed scope: api Everything related to the API priority: urgent labels May 13, 2024
@rajdip-b rajdip-b moved this to Todo in keyshade-api May 13, 2024
@jamesfrye420
Copy link
Contributor

Can it be possibily because the JWTModule is trying to access env vars before they are read in the config module?

That would indicate that the JwtModule is being initialized before the config module is ready.

Could you verify this?

@rajdip-b
Copy link
Member Author

The JWT code I linked belongs from the auth module. And in the top level app module, config module is initialised at the very beginning. So I'm doubtful if that might be the cause (I checked it the first thing).

@rajdip-b
Copy link
Member Author

@jamesfrye420 could you link the PR? The solution you showed would work for now.

@jamesfrye420
Copy link
Contributor

Sure, I just wanna check something before I push the pr. Will keep you updated

@rajdip-b rajdip-b moved this from Todo to Under review in keyshade-api Jun 3, 2024
@shubham9069
Copy link

@rajdip-b Is this solved ? if it is still open so i can work on this

@rajdip-b
Copy link
Member Author

rajdip-b commented Jul 3, 2024

Not really, but this isnt a priority at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: 4 help wanted Extra attention is needed priority: low scope: api Everything related to the API type: bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants