Closed singhayushh closed 3 years ago
If you check the login route, whenever a user logs in, a jwt token with the user's email and _id encrypted is passed to the client side. Now, whenever there is any request from the client side, this token is passed along with the request in the header.
What this middleware does is it tries to access the token from the request header. If found, the code then checks for its validity. If the token is valid, the user's email and _id can be extracted, thereby verifying that the user was signed in. And we have all the information of who sent the request just by fetching details from the User collection by passing the above mail or the _id.
If the token isn't found or isn't valid, immediately a response is returned with corresponding message and the flow never reaches the route handler function.
Fixes #131
Changes done
middlewares
with the code for user authentication middlewareScreenshots of the changes (If any) -
Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.
✅️ By submitting this PR, I have verified the following