Role-Based Login System

Production-ready authentication system that implements role-based access control, JWT sessions, activity auditing, and secure password flows. Ships with an administrative console, onboarding flows, and self-service profile management.

Next.jsNode.jsPostgreSQLPrismaNextAuthDocker
Role-Based Login System preview

Role-Based Login System with Authentication and Authorization

This project is a role-based login system designed to provide secure access control for different users: Schools, Parents, and Students. The system ensures that each type of user can access specific features based on their role.

Table of Contents

Features

  • User registration and login
  • Email verification
  • Role-based access control
  • JWT authentication
  • Password reset functionality
  • CRUD operations for student achievements

Technologies Used

  • Node.js
  • Express.js
  • TypeScript
  • Prisma (ORM)
  • PostgreSQL
  • JWT (JSON Web Tokens)
  • Nodemailer
  • Zod (Validation)

Project Structure

Setup and Installation

  1. Clone the repository:

    sh
    git clone https://github.com/theanant404/Role-Based-Login-System-with-Authentication-Authorization.git cd Role-Based-Login-System-with-Authentication-Authorization/server
  2. Install dependencies:

    sh
    npm install
  3. Set up environment variables:

    • Create a
      terminal
      .env
      file in the server directory.
    • Copy the contents of .env.sample into
      terminal
      .env
      and fill in the required values.
  4. Set up the database:

    • Ensure you have PostgreSQL installed and running.
    • Update the
      terminal
      DATABASE_URL
      in the
      terminal
      .env
      file with your PostgreSQL connection string.
    • Run the Prisma migrations to set up the database schema:
    sh
    npx prisma migrate dev

Running the Project

  1. Build the project:

    sh
    npm run build
  2. Start the server:

    sh
    npm run start
  3. For development:

    sh
    npm run dev

    This will start the server with hot-reloading enabled.

API Endpoints

Auth Routes

  • POST /auth/register - Register a new user
  • POST /auth/verify-email - Verify user email with OTP
  • GET /auth/login - Login user
  • POST /auth/forgot-password - Send OTP for password reset
  • POST /auth/reset-password - Reset user password
  • POST /auth/logout - Logout user

Dashboard Routes

  • GET /dashboard/ - Get user dashboard
  • GET /dashboard/student/:id - Get student details (School role only)
  • POST /dashboard/add-achievement/:id - Add new achievement (School role only)
  • DELETE /dashboard/deleteachievement/:id - Remove student achievement (School role only)
  • DELETE /dashboard/deleteuser/:id - Delete user (School role only)

Environment Variables

The following environment variables need to be set in the

terminal
.env
file:

License

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

Highlights
  • Role-based access control with customizable policies
  • Secure authentication with JWT rotation
  • Audit logging and activity timelines
  • Self-service onboarding and profile management
  • Protects API routes with middleware guards
Key Challenge

Ensured secure session handling and minimized privilege escalation risk while keeping onboarding frictionless.

Anant Kumar

Bridging the gap between high-level applications and low-level systems. Crafting resilient software with a focus on performance and observability.

Expertise

  • Systems Engineering
  • Full Stack Development
  • Cloud Infrastructure
  • Digital Signal Processing
  • Embedded Systems

Stay Connected

Open to opportunities and interesting conversations.

Get in Touch

© 2026 Anant Kumar. All rights reserved.

Systems Operational