As a backend developer, I need to add authentication middleware for all "Have" and "Need" POST routes to ensure that only authenticated users can create new items. This middleware will enhance the security of the application by restricting unauthorized access to these endpoints.
Acceptance Criteria
Develop authentication middleware to verify the presence of valid user authentication tokens for all "Have" and "Need" POST routes.
Integrate the authentication middleware into the route handlers for creating "Have" and "Need" items.
Ensure that the authentication middleware validates the authentication token in the request headers.
Return a 401 Unauthorized response if the authentication token is missing or invalid.
Implement logging mechanisms to record unauthorized access attempts for auditing purposes.
Test the authentication middleware thoroughly to verify its functionality and reliability.
Document the authentication middleware, including its purpose, input requirements, and usage guidelines.
Ensure seamless integration of the authentication middleware with the existing backend architecture.
Coordinate with the frontend team to ensure proper handling of authentication errors on the client side.
Goal
decode the JWT token on POST requests
Decoded token should contain user information
Attach user information to res.locals object
To be used in Have/Need controller functions for User references const {_id } = res.locals
Testing
Use Postman to send POST requests to "Have" and "Need" routes with valid authentication tokens.
Verify that the requests are processed successfully and the items are created.
Attempt to send requests without authentication tokens and verify that the middleware rejects them with a 401 Unauthorized response.
Description:
As a backend developer, I need to add authentication middleware for all "Have" and "Need" POST routes to ensure that only authenticated users can create new items. This middleware will enhance the security of the application by restricting unauthorized access to these endpoints.
Acceptance Criteria
Goal
res.locals
objectconst {_id } = res.locals
Testing