Skip to content

cisdevoe/lab_auth_api_3isc

Repository files navigation

Lab: Authentication API (Express + MySQL + JWT)

This project is an Authentication API built with Express.js, MySQL, JWT, and bcrypt.
It supports user signup, login, logout (token revocation), and a protected /profile route.


⚙️ Setup

  1. Clone & install

git clone https://github.com/your-username/lab-auth-api.git cd lab-auth-api npm install

  1. Create .env Create a .env file (see .env.example).

  2. Create DB & tables Run in MySQL: CREATE DATABASE lab_auth; USE lab_auth;

CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(100) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, full_name VARCHAR(120), role VARCHAR(30) DEFAULT 'student', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );

CREATE TABLE revoked_tokens ( id INT AUTO_INCREMENT PRIMARY KEY, jti VARCHAR(64) NOT NULL UNIQUE, expires_at DATETIME NOT NULL, revoked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );

  1. Run server npm run dev

📡 Endpoints Public

  • POST /auth/signup → register a new user
  • POST /auth/login → login, receive JWT
  • Protected (requires Authorization: Bearer )
  • GET /profile → get current user info
  • POST /auth/logout → revoke token

🔑 Testing (Postman)

  • Signup → create a user
  • Login → copy JWT token
  • Profile → call /profile with Authorization: Bearer
  • Logout → revoke token
  • Retry /profile → should return 401 token revoked

🚨 Notes

  • Keep .env private (never commit).
  • Use .env.example as a template.
  • Replace JWT_SECRET with a long random string.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published