A secure authentication system built with Node.js, Express, Prisma, and JWT.
- User registration with email verification
- Login with JWT authentication
- Refresh token mechanism
- Password reset functionality
- Secure user profile access
- Logout and token revocation
- 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
- Node.js installed
- PostgreSQL or any Prisma-supported database set up
- Clone the repository:
git clone https://github.com/akgbytes/authentication-system.git cd authentication-system
- Install dependencies:
npm install
- 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"
- Create a
- Run Prisma migrations:
npx prisma migrate dev --name init
- Start the server:
npm start
- 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
/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
Pull requests are welcome! Feel free to fork the repo and submit a PR.
This project is open-source and available under the ISC License.