Task Description: Implement User Authentication Feature
You are required to develop a user authentication feature in the application located in the /app/ directory. This feature should allow users to register, log in, and log out. The specific functionality to be implemented includes the following:
User Registration:
Create an endpoint /api/register that accepts user details such as username, password, and email.
Ensure that the username is unique and the email is valid. Store the user information securely, hashing the password before saving it to the database.
Return a success message and a confirmation of user registration.
User Login:
Implement an endpoint /api/login that receives username and password.
Verify the credentials against the stored data. If valid, generate a JWT (JSON Web Token) for the session and return it to the user along with a success message.
If the credentials are incorrect, return an appropriate error message.
User Logout:
Implement an endpoint /api/logout that invalidates the user’s session by clearing the JWT token from client-side storage (e.g., cookies or local storage).
Return a success message confirming that the user has been logged out.
Error Handling:
Ensure that all endpoints return appropriate HTTP status codes and messages for successful operations as well as errors (e.g., 400 for bad requests, 401 for unauthorized, etc.).
Testing:
All implemented functionality must be accompanied by relevant unit and integration tests. Make sure to handle edge cases (e.g., duplicate usernames, empty fields, etc.) to ensure robustness.
Upon successful completion of these tasks, all existing tests concerning user authentication should pass. The solution must be structured and maintainable, following best practices for RESTful API development.