NestJS-based ecommerce API with authentication and role-based access control.
- JWT Authentication
- Role-based access (Admin, Seller, Buyer)
- MySQL database with Drizzle ORM
- Zod validation
- Password hashing with bcrypt
- Install dependencies:
npm install
- Set up environment variables:
cp .env.example .env
Edit .env
with your database credentials.
- Generate and run database migrations:
npm run db:generate
npm run db:migrate
- Start the development server:
npm run start:dev
POST /auth/register
- Register new userPOST /auth/login
- Login userGET /auth/profile
- Get user profile (protected)GET /auth/admin-only
- Admin only endpointGET /auth/seller-access
- Seller/Admin endpoint
Register:
{
"email": "user@example.com",
"password": "password123",
"firstName": "John",
"lastName": "Doe",
"role": "buyer"
}
Login:
{
"email": "user@example.com",
"password": "password123"
}
admin
- Full accessseller
- Can manage products (future feature)buyer
- Can purchase products (future feature)