Skip to content

Repository files navigation

🚀 Fullstack Authentication Server 🛡️

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.

✨ Features

  • 🔒 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.

🛠️ Installation

Follow these steps to get the project running locally:

  1. Clone the Repository:

    git clone https://github.com/amnesia2k/fullstack.git
    cd server
  2. Install Dependencies:

    pnpm install
  3. 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
    
  4. Database Setup:

    • Run the database migrations:
    pnpm db:push
  5. Start the Server:

    pnpm dev

💻 Usage

Endpoints

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"
}

Middleware

  • 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.

✨ Key Features

  • ✔️ 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.

🛠️ Technologies Used

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

🤝 Contributing

Contributions are welcome! Here's how you can contribute:

  • Report bugs 🐛
  • Suggest enhancements ✨
  • Submit pull requests 🛠️

Contribution Guidelines

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes with clear and concise messages.
  4. Push your branch to your forked repository.
  5. Submit a pull request.

📜 License

This project is licensed under the MIT License.

👨‍💻 Author Info

Readme was generated by Dokugen

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages