This project is an Express.js API for user authentication using MySQL as the database. It provides endpoints for user registration, login, token refresh, user verification, and logout.
-
Clone the repository:
git clone https://github.com/armanmartirosyan/login-api.git
-
Install dependencies:
cd login-api npm install
- GET /auth/verify-user: Verify if a user is logged in.
- POST /auth/login: Login a user and obtain access and refresh tokens.
- POST /auth/register: Register a new user and obtain access and refresh tokens.
- POST /auth/refresh-token: Refresh the access and refresh tokens.
- DELETE /auth/logout: Logout a user.
-
POST /auth/login
{ "email": "user@example.com", "password": "password" }
-
Response:
{ "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", }
For more details on request payloads and responses for each endpoint, please refer to the source code.
The script for generating access and refresh tokens is stored in the helpers
folder. To use it, navigate to the project directory and run the following command:
node ./helpers/generateKeys.js
You'll need to set up a MySQL database with at least the following tables:
- users
- id (int, auto_increment, primary key)
- name (varchar)
- email (varchar)
- password (varchar)
- invalidated_tokens
- id (int, auto_increment, primary key)
- token (varchar)
- invalidated_at (timestamp)
This project is licensed under the MIT License - see the LICENSE file for details.