A robust and scalable authentication system built with Node.js, Express.js, TypeScript, and MongoDB, utilizing JSON Web Tokens (JWT) for secure authentication. This project serves as a foundation for any Node.js application requiring user registration, login, and role-based access control.
- User Registration: Secure user registration with password hashing.
- User Login: Authentication using JWT, with token generation.
- Role-Based Access Control: Basic user roles (e.g., user, admin) for managing access.
- Middleware for Authentication: Protect routes with custom middleware to ensure only authenticated users can access them.
- TypeScript for Strong Typing: Fully typed project to catch errors early and improve maintainability.
POST /auth/register
- Register a new userPOST /auth/login
- Login and obtain a JWTPOST /auth/verify-email
- Verify a user's email addressPOST /auth/forgot-password
- Send a password reset emailPOST /auth/reset-password
- Reset a user's passwordPOST /auth/logout
- Logout a user (protected)
GET /users
- Get all users (protected)GET /users/:id
- Get user details by ID (protected)PUT /users/:id
- Update user details by ID (protected)DELETE /users/:id
- Delete a user (protected)
To get started with this project, clone the repository and install the dependencies:
git clone https://github.com/ferhatkefsiz/express-auth-system.git
cd express-auth-system
npm install
Create a .env
file in the root of the project and add the following variables:
PORT=
TOKEN_SECRET=
MONGODB_URI=
RESEND_API_KEY=
EMAIL_SENDER=onboarding@resend.dev
EMAIL_RECIPIENT=
CLIENT_URL=
To start the development server, use the following command:
npm run start:dev
Contributions are welcome! Please fork this repository and submit a pull request for any enhancements or bug fixes.