This project is a secure authentication system built using Node.js, Express, MongoDB, and JWT, following Domain-Driven Design (DDD) and adhering to SOLID principles. It provides multiple authentication methods, including password-based login and OTP-based login, with email verification via Nodemailer.
- π User Registration with email and password
- π§ Email Verification through OTP
- π Secure Authentication with JWT
- π Password-based Login
- π’ OTP-based Login
- π Token-based Authorization
- π Resend OTP functionality
- π‘οΈ Middleware for Protected Routes
- π Backend: Node.js, Express.js
- ποΈ Database: MongoDB (Mongoose ODM)
- π Authentication: JWT, bcrypt for password hashing
- π§ Email Service: Nodemailer with SMTP
- π‘οΈ Validation: Zod
- π Security: CORS, dotenv for environment configuration
/backend
βββ /src
β βββ /domain
β β βββ services
β β β βββ AuthService.js
β βββ /infrastructure
β β βββ models
β β β βββ otp.js
β β β βββ user.js
β β βββ email
β β βββ EmailService.js
β β βββ db.js
β βββ /presentation
β β βββ middleware
β β βββ auth.js
β β βββ routes
β β βββ otp.js
β β βββ signin.js
β β βββ signup.js
β βββ index.js
/frontend
βββ /src
β βββ /components
β β βββ Dashboard.jsx
β β βββ MainPage.jsx
β β βββ SignInOtp.jsx
β β βββ SignInPassword.jsx
β β βββ SignUp.jsx
β βββ App.jsx
git clone https://github.com/Mayankkamriya/UnihoxTask.git
cd backend
npm install
cd src
node index.js
cd frontend
npm install
npm run dev
Create a .env
file in the backend folder:
MONGODB_URI=your-mongodb-connection-string
JWT_SECRET=your-secret-key
EMAIL=your-email
PASS=your-email-password
HOST=smtp.example.com
Create a .env
file in the frontend folder:
VITE_API_URL=http://localhost:3000
VITE_JWT_SECRET=your-secret-key
http://localhost:3000
Method | Endpoint | Description |
---|---|---|
POST | /api/v1/signup |
Register a new user |
POST | /api/v1/signin/password |
Login with email and password |
POST | /api/v1/signin/request-otp |
Request OTP for login |
POST | /api/v1/signin/otp |
Verify OTP and login |
POST | /api/v1/resendOTP |
Resend OTP |
GET | /api/v1/dashboard |
Protected route (requires authentication) |
π Live Demo: https://unihox-task.vercel.app
Mayank Kamriya
B.B.A. - Vikram University
π LinkedIn
π§ [email protected]
π +91 8253038815
Made with β€οΈ by Mayank Kamriya