Skip to content

akgbytes/authentication-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prisma Authentication Backend

A secure authentication system built with Node.js, Express, Prisma, and JWT.

Features

  • User registration with email verification
  • Login with JWT authentication
  • Refresh token mechanism
  • Password reset functionality
  • Secure user profile access
  • Logout and token revocation

Technologies Used

  • Node.js & Express - Backend framework
  • Prisma - ORM for database management
  • JWT (jsonwebtoken) - Authentication tokens
  • bcryptjs - Password hashing
  • Nodemailer - Email sending for verification & password reset
  • cookie-parser - Handling authentication tokens in cookies
  • dotenv - Environment variable management
  • CORS - Cross-origin requests handling

Installation

Prerequisites

  • Node.js installed
  • PostgreSQL or any Prisma-supported database set up

Steps

  1. Clone the repository:
    git clone https://github.com/akgbytes/authentication-system.git
    cd authentication-system
  2. Install dependencies:
    npm install
  3. Configure environment variables:
    • Create a .env file in the root directory
    • Add the following variables:
      DATABASE_URL=your_database_url
      PORT=8080
      ACCESS_TOKEN_SECRET=your_access_token_secret
      ACCESS_TOKEN_EXPIRY=5m
      REFRESH_TOKEN_SECRET=your_refresh_token_secret
      REFRESH_TOKEN_EXPIRY=7d
      SMTP_HOST=your_smtp_host
      SMTP_PORT=your_smtp_port
      SMTP_USER=your_smtp_email
      SMTP_PASS=your_smtp_password
      MAILTRAP_HOST=your_mailtrap_host
      MAILTRAP_PORT=your_mailtrap_port
      MAILTRAP_USERNAME=your_mailtrap_username
      MAILTRAP_PASSWORD=your_mailtrap_password
      MAILTRAP_SENDERMAIL=your_mailtrap_email
      
      FRONTEND_URL="http://localhost:5173"
  4. Run Prisma migrations:
    npx prisma migrate dev --name init
  5. Start the server:
    npm start

API Endpoints

Auth Routes

  • POST /api/v1/user/register - Register a new user
  • POST /api/v1/user/verify/:token - Verify email
  • POST /api/v1/user/login - Login user
  • GET /api/v1/user/profile - Get user profile (protected)
  • POST /api/v1/user/forgot-password - Send password reset link
  • POST /api/v1/user/reset-password/:resetToken - Reset password
  • GET /api/v1/user/logout - Logout user
  • POST /api/v1/user/refresh-token - Refresh access token

Project Structure

/authentication-system
│── prisma/                # Prisma schema & migrations
│── src/
│   ├── controllers/       # Authentication logic
│   ├── middleware/        # Middleware for authentication
│   ├── routes/            # API routes
│   ├── utils/             # Utility functions
│   ├── index.js           # Entry point
│── .env.example           # Example environment variables
│── package.json           # Dependencies and scripts
│── README.md              # Documentation

Contributing

Pull requests are welcome! Feel free to fork the repo and submit a PR.

License

This project is open-source and available under the ISC License.

Repository

GitHub

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published