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.

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
- Technologies Used
- Project Structure
- Setup and Installation
- Running the Project
- API Endpoints
- Environment Variables
- License
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
-
Clone the repository:
shgit clone https://github.com/theanant404/Role-Based-Login-System-with-Authentication-Authorization.git cd Role-Based-Login-System-with-Authentication-Authorization/server -
Install dependencies:
shnpm install -
Set up environment variables:
- Create a file in the server directory.terminal
.env - Copy the contents of .env.sample into and fill in the required values.terminal
.env
- Create a
-
Set up the database:
- Ensure you have PostgreSQL installed and running.
- Update the in theterminal
DATABASE_URLfile with your PostgreSQL connection string.terminal.env - Run the Prisma migrations to set up the database schema:
shnpx prisma migrate dev
Running the Project
-
Build the project:
shnpm run build -
Start the server:
shnpm run start -
For development:
shnpm run devThis 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
.env- - PostgreSQL connection stringterminal
DATABASE_URL - PORT - Server port
- SMTP_HOST - SMTP host for sending emails
- SMTP_PORT - SMTP port
- SMTP_USER - SMTP user
- SMTP_PASSWORD - SMTP password
- FROM_EMAIL - Email address to send emails from
- ACCESS_TOKEN_SECRET - Secret key for access token
- REFRESH_TOKEN_SECRET - Secret key for refresh token
License
This project is licensed under the MIT License. See the LICENSE file for details.
- 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
Ensured secure session handling and minimized privilege escalation risk while keeping onboarding frictionless.