Built by Daud Abdi
π Live Demo: http://3.10.174.145:4000
π» GitHub: View Source
π§ Contact: daudsaidabdi@gmail.com
π± Portfolio: daud-abdi-portfolio-site.vercel.app
A production-ready authentication and authorization API built with Node.js, Express, TypeScript, and PostgreSQL. Deployed on AWS infrastructure with JWT-based authentication, email verification, and role-based access control.
- π User registration with email verification
- π« JWT-based authentication (access + refresh tokens)
- π Automatic token refresh mechanism
- π Secure password reset flow
- π₯ Role-based access control (user/admin)
- π§ Email notifications (verification, password reset)
- π‘οΈ bcrypt password hashing
- β Input validation and error handling
- π§ͺ Comprehensive test coverage with Jest
Backend:
- Node.js
- Express.js
- TypeScript
- PostgreSQL
- JWT (jsonwebtoken)
- bcrypt
Deployment:
- AWS EC2 (Ubuntu 24.04)
- AWS RDS (PostgreSQL)
- PM2 Process Manager
- SSL/TLS Database Connection
Testing:
- Jest
- Supertest
POST http://3.10.174.145:4000/api/auth/register
Content-Type: application/json
{
"username": "johndoe",
"email": "john@example.com",
"password": "SecurePass123!"
}POST http://3.10.174.145:4000/api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "SecurePass123!"
}POST http://3.10.174.145:4000/api/auth/refresh
Content-Type: application/json
{
"refreshToken": "your_refresh_token_here"
}POST http://3.10.174.145:4000/api/auth/forgot-password
Content-Type: application/json
{
"email": "john@example.com"
}GET http://3.10.174.145:4000/api/auth/profile
Authorization: Bearer your_access_token_hereGET http://3.10.174.145:4000/healthGET http://3.10.174.145:4000/βββββββββββββββββββββββββββββββββββ
β AWS EC2 (Ubuntu 24.04) β
β Node.js + Express + PM2 β
β Port: 4000 β
βββββββββββββββ¬ββββββββββββββββββββ
β
β SSL Connection
βΌ
βββββββββββββββββββββββββββββββββββ
β AWS RDS PostgreSQL 17.6 β
β - users table β
β - refresh_tokens table β
β - password_reset_tokens β
βββββββββββββββββββββββββββββββββββ
- Node.js 18+
- PostgreSQL 14+
- npm or yarn
- Clone the repository
git clone https://github.com/Daudsaid/authentication-authorization-api.git
cd authentication-authorization-api- Install dependencies
npm install- Set up environment variables
Create a .env file:
PORT=4000
DATABASE_URL=postgresql://username:password@localhost:5432/auth_db
JWT_ACCESS_SECRET=your_access_secret_here
JWT_REFRESH_SECRET=your_refresh_secret_here
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_app_password
CLIENT_URL=http://localhost:3000
NODE_ENV=development- Set up database
# Create database
createdb auth_db
# Run schema (see src/__tests__/setup/testDb.helper.ts for table definitions)- Run development server
npm run devThe API will be available at http://localhost:4000
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch# Build TypeScript to JavaScript
npm run build
# Start production server
npm start- β Password hashing with bcrypt (10 rounds)
- β JWT tokens with expiration
- β Refresh token rotation
- β HTTPS/SSL database connections
- β Environment variable management
- β Input validation and sanitization
- β SQL injection protection (parameterized queries)
- β CORS configuration
users
βββ id (SERIAL PRIMARY KEY)
βββ username (VARCHAR UNIQUE)
βββ email (VARCHAR UNIQUE)
βββ password (VARCHAR - hashed)
βββ role (VARCHAR - 'user'/'admin')
βββ is_verified (BOOLEAN)
βββ verification_token (VARCHAR)
βββ created_at (TIMESTAMP)
βββ updated_at (TIMESTAMP)
refresh_tokens
βββ id (SERIAL PRIMARY KEY)
βββ user_id (INTEGER FK β users.id)
βββ token (VARCHAR UNIQUE)
βββ expires_at (TIMESTAMP)
βββ created_at (TIMESTAMP)
password_reset_tokens
βββ id (SERIAL PRIMARY KEY)
βββ user_id (INTEGER FK β users.id)
βββ token (VARCHAR UNIQUE)
βββ expires_at (TIMESTAMP)
βββ used (BOOLEAN)
βββ created_at (TIMESTAMP)- OAuth 2.0 integration (Google, GitHub)
- Two-factor authentication (2FA)
- Rate limiting middleware
- API documentation with Swagger/OpenAPI
- Docker containerization
- CI/CD pipeline with GitHub Actions
MIT License
Daud Abdi
- Portfolio: daud-abdi-portfolio-site.vercel.app
- LinkedIn: linkedin.com/in/daudabdi0506
- GitHub: @Daudsaid
- Email: daudsaidabdi@gmail.com
- Built as part of my full-stack development portfolio
- Deployed on AWS to demonstrate cloud infrastructure skills
- Following industry best practices for authentication systems
β If you found this project helpful, please consider giving it a star!
Made with β€οΈ by Daud Abdi