@coconut-packages/um-middlewares
v0.0.3
Published
/** * Middleware to authenticate JWT tokens in incoming HTTP requests. * * Extracts the Bearer token from the `Authorization` header, verifies its validity, * and attaches the corresponding user object to the request if authentication succeeds.
Readme
/**
- Middleware to authenticate JWT tokens in incoming HTTP requests.
- Extracts the Bearer token from the
Authorizationheader, verifies its validity, - and attaches the corresponding user object to the request if authentication succeeds.
- Responds with appropriate HTTP status codes and error messages if:
- The token is missing (401 Unauthorized)
- The token is invalid or expired (403 Forbidden)
- The user associated with the token does not exist (404 Not Found)
- @param {Object} req - Express request object, expects
authorizationheader andmongooseinstance. - @param {Object} res - Express response object, used to send error responses.
- @param {Function} next - Express next middleware function.
- @returns {void} */
