Skip to content

enyoghasim/node-ts-auth-bootstrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Authentication Bootstrap Server

A robust authentication server template built with Node.js, TypeScript, Express.js, MongoDB and Redis.

Technologies Used

  • Node.js & TypeScript
  • Express.js
  • MongoDB with Mongoose
  • Redis
  • Express Session
  • Joi for validation

Prerequisites

  • Node.js (v17+)
  • MongoDB
  • Redis
  • TypeScript

Environment Variables

Create a .env file in the root directory:

PORT=58303
MONGODB_URI="mongodb://localhost:27017/your_database"
SESSION_SECRET="your_session_secret"
CLIENT_URL="http://localhost:3000"

REDIS_HOST="localhost"
REDIS_PORT="6379"
REDIS_PASSWORD=""

Installation & Running

Using npm

# Install dependencies
npm install

# Run in development
npm run dev

# Build for production
npm run build

# Start production server
npm start

Using yarn

# Install dependencies
yarn install

# Run in development
yarn dev

# Build for production
yarn build

# Start production server
yarn start

API Endpoints

Authentication Routes (/api/v1/auth)

  • POST /signup

    • Register new user
    • Body:
      {
        "fullname": "John Doe",
        "email": "john@example.com",
        "password": "Password123",
        "confirmPassword": "Password123"
      }
  • POST /signin

    • Login existing user
    • Body:
      {
        "email": "john@example.com",
        "password": "Password123"
      }
  • GET /signout

    • Logout user
    • Requires authentication
  • POST /forgot-password

    • Request password reset
    • Body:
      {
        "email": "john@example.com"
      }
  • POST /reset-password/:selector/:token

    • Reset password with token
    • Body:
      {
        "password": "NewPassword123",
        "confirmPassword": "NewPassword123"
      }

User Routes (/api/v1/user)

  • GET /
    • Get current user profile
    • Requires authentication

Password Requirements

  • Minimum 8 characters
  • At least one uppercase letter
  • At least one number

Session Management

  • Sessions stored in Redis
  • Cookie expires in 14 days
  • Single active session per user

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published