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

Enhance JWT Token Management #102

Merged
merged 3 commits into from
Oct 13, 2024
Merged

Conversation

RishiVT2004
Copy link
Contributor

@RishiVT2004 RishiVT2004 commented Oct 12, 2024

Fixed Issue #99

Changes Made to the codebase

1. Added Middleware for Environment Variable Validation

Introduced a checkKey middleware function to validate the presence of ACCESS_TOKEN_SECRET in environment variables
and assign it to req.Key for use in subsequent functions.

2. Refactored generateAccessToken Function

Improved error handling with specific messages for token generation failure and server errors.
Returned the token as a JSON object with a clear key.

3. Improved decodeAccessToken Function

Streamlined error checking for the authorization header.
Removed redundant checks and ensured the function handles decoding the token appropriately.
Returned error messages with appropriate status codes for missing authorization headers, token decoding failures, and invalid or expired tokens.

4. Consistent Error Responses

Ensured that all error responses are formatted consistently with proper status codes and messages.

@RishiVT2004
Copy link
Contributor Author

@Harshdev098 please review this pr and add necessary tags(hacktoberfest and gssoc)

Copy link
Owner

@Harshdev098 Harshdev098 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its giving error, I think its because you have changed the parameters of the generateAccessToken and decodeAccessToken , and its very overwhelming to update these functions in every files, if there is any other method to add the middleware you can go with it, or discard the changes done for setting the middleware checkKey because i think its not that necessary

@Harshdev098
Copy link
Owner

OR you can update the functions in the files

@RishiVT2004
Copy link
Contributor Author

RishiVT2004 commented Oct 13, 2024

@Harshdev098 i think refactoring the code will cause too much issue in the future , let me try to simplify and change the code according to your needs

@Harshdev098
Copy link
Owner

Yah, right

@RishiVT2004
Copy link
Contributor Author

@Harshdev098 check if this is good enough or not and let me know

@Harshdev098 Harshdev098 merged commit 2cae88f into Harshdev098:main Oct 13, 2024
1 check passed
@Harshdev098 Harshdev098 added hacktoberfest This issue belongs to hacktoberfest gssoc-ext This issue is under GSSoc Ext program hacktoberfest-accepted label for accepted PRs under hacktoberfest level2 level2 lebel for gssoc level labels Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gssoc-ext This issue is under GSSoc Ext program hacktoberfest This issue belongs to hacktoberfest hacktoberfest-accepted label for accepted PRs under hacktoberfest level2 level2 lebel for gssoc level
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants