Company: Unicult_8oct
Difficulty: medium
Problem Description Implement a REST API in Node.js to manage user authentication using JSON Web Tokens (JWT). The application uses the Sequelize ORM to interact with a User database model. Your task is to implement the endpoints to issue a new JWT upon successful login, persist the token to the database, and validate existing tokens. Endpoints POST /login : Authenticates a user, generates a JWT, updates the database with the token, and returns the token. POST /validate : Decodes and verifies a provided JWT and returns the associated username. Request Format POST /login Expects a JSON body containing the user's credentials: { "username": "Jarvisporter", "password": "myfewsord" } POST /validate Expects a JSON body containing the JWT to validate: { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." } Response Format POST /login Success (200 OK): Returns the newly generated JWT: { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." } POST /validate Success (200 OK): Returns the extracted u