Skip to content

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.

License

Notifications You must be signed in to change notification settings

armanmartirosyan/login-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express MySQL Auth API

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.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/armanmartirosyan/login-api.git
  2. Install dependencies:

    cd login-api
    npm install

Usage

Endpoints

  • 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.

Request/Response Payloads

  • 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.

Dependencies

Generating Keys

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

Database Schema

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)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published