Implement JWT Authentication and Return Token in Login Response #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description:
This pull request addresses the following issue:
This pull request introduces several key updates to the project:
Implemented the
express.json()
middleware to handle JSON data. This middleware enhances the server's capability to parse incoming JSON payloads from requests, enabling seamless handling of JSON data throughout the application.Added a new route,
/users
, which serves as a test for private routes that require JWT tokens for authentication. This route provides an example of a protected endpoint that requires a valid JWT token for access.Integrated the
dotenv
package to facilitate loading sensitive data from the.env
file. This approach enhances security by allowing the storage of environment-specific configurations and sensitive information (e.g., secret keys or database credentials) in a separate and secure location.Implemented logic to generate a JWT token when a user logs in. This logic handles the authentication process and returns a JWT token that can be utilized for subsequent authenticated requests.
Added a
userController
router to facilitate testing of theverifyToken
middleware. This router includes various endpoints related to user operations and serves as a demonstration of how theverifyToken
middleware can be applied to protected routes.Created a
userRoute
file to define specific routes related to user operations. This file primarily focuses on the implementation of theverifyToken
middleware to ensure that certain routes require valid JWT tokens for access.Developed the
verifyToken
middleware function, which authenticates the validity of the client's JWT token. This middleware function acts as a security measure by confirming the authenticity of the token before granting access to protected routes.Added the required dependencies,
jsonwebtoken
anddotenv
, to facilitate token generation and the secure loading of sensitive environment-specific data, respectively.These updates significantly enhance the security and functionality of the project, enabling the implementation of private routes that require valid JWT tokens for authentication.