A robust and scalable authentication server built with TypeScript, Drizzle ORM, and Express.js. This project provides a solid foundation for user registration, login, and secure access management.
- 🔒 Secure Authentication: Utilizes JWT for secure user authentication.
- 🛡️ Role-Based Access Control (RBAC): Implements RBAC to manage user permissions.
- ⚙️ Configuration: Uses .env files for easy configuration.
- 🗄️ Database Migrations: Uses Drizzle for database schema management and migrations.
- ✅ Validation: Employs Zod for robust data validation.
Follow these steps to get the project running locally:
-
Clone the Repository:
git clone https://github.com/amnesia2k/fullstack.git cd server -
Install Dependencies:
pnpm install
-
Set Up Environment Variables:
- Create a .env file based on .env.example.
- Update the environment variables with your actual values.
PORT=8000 DATABASE_URL="your_database_url_here" JWT_SECRET=your_jwt_secret_key -
Database Setup:
- Run the database migrations:
pnpm db:push
-
Start the Server:
pnpm dev
Register a new user.
POST /api/v1/register:
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "securePassword"
}Login an existing user.
POST /api/v1/login:
{
"email": "john.doe@example.com",
"password": "securePassword"
}-
POST /api/v1/logout: Logout the current user. -
GET /api/v1/users: Get all users (Admin only). -
GET /api/v1/user: Get the current user's information.
Update the current user's information.
PATCH /api/v1/user:
{
"name": "Updated Name",
"bio": "Updated bio information"
}DELETE /api/v1/delete: Delete the current user's account.
Delete a user by ID (Admin only).
DELETE /api/v1/admin/delete:
{
"_id": "user_id_to_delete"
}- validateData: Validates request body against a Zod schema.
- validateToken: Validates JWT token and attaches user info to the request.
- validateUserRole: Validates user role against allowed roles.
- ✔️ User Authentication: Securely manage user registration and login.
- 🛡️ Role-Based Access Control: Control access based on user roles (user, creator, admin).
- 🔑 JWT Authentication: Use JSON Web Tokens for authentication.
- 🗄️ Database Migrations: Easily manage database schema changes with Drizzle.
- 🔒 Password Hashing: Securely hash and compare passwords using bcryptjs.
- 🍪 Cookie Management: Utilizes cookies for token storage.
- 🌐 CORS: Configured for Cross-Origin Resource Sharing.
| Technology | Link |
|---|---|
| TypeScript | https://www.typescriptlang.org/ |
| Express.js | https://expressjs.com/ |
| Drizzle ORM | https://orm.drizzle.team/ |
| Zod | https://zod.dev/ |
| JSON Web Token | https://jwt.io/ |
| bcryptjs | https://www.npmjs.com/package/bcryptjs |
| pnpm | https://pnpm.io/ |
| Cors | https://www.npmjs.com/package/cors |
| Cookie Parser | https://www.npmjs.com/package/cookie-parser |
Contributions are welcome! Here's how you can contribute:
- Report bugs 🐛
- Suggest enhancements ✨
- Submit pull requests 🛠️
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with clear and concise messages.
- Push your branch to your forked repository.
- Submit a pull request.
This project is licensed under the MIT License.