The Auth Service is a Node.js microservice responsible for user authentication and authorization in the 3D Architectural Design Platform. It provides secure user registration, login, JWT-based authentication, password reset via OTP, Google OAuth, and user profile management. This service is designed to be used as part of a microservices architecture and can be deployed independently.
auth-service/
βββ config/ # Database and environment configuration
β βββ index.js
βββ controllers/ # Business logic for authentication
β βββ auth.controller.js
βββ middlewares/ # Express middlewares (e.g., authentication)
βββ models/ # Mongoose schemas
β βββ user.model.js
βββ routes/ # Express route definitions
β βββ auth.routes.js
βββ services/ # (Optional) Service layer for business logic
βββ utils/ # Utility functions (email, token, verification)
β βββ email.js
β βββ token.js
β βββ verification.js
βββ validations/ # (Optional) Request validation logic
βββ .env # Environment variables
βββ Dockerfile # Docker configuration
βββ docker-compose.yml
βββ package.json
βββ Readme.md
βββ src/
βββ app.js # Main Express app entry point
- User Registration & Login (with username/email)
- JWT-based Authentication (access tokens via cookies)
- Google OAuth2 Login
- Password Reset via OTP (email-based)
- Profile Management (get, update, delete)
- Email Verification (token-based, optional)
- Secure Middleware Protection
- Docker & Docker Compose Support
- Environment-based Configuration
- Node.js with Express
- MongoDB with Mongoose
- JWT for Authentication
- bcrypt for Password Hashing
- dotenv, cors, cookie-parser
Create a .env file in the project root with the following variables:
PORT=4000
MONGODB_URI=mongodb://localhost:27017/auth_service
JWT_SECRET=your_jwt_secret
GOOGLE_CLIENT_ID=your_google_client_id
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your_email@example.com
SMTP_PASS=your_email_password
FRONTEND_URL=http://localhost:5173All endpoints are prefixed with /api/v1.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /register |
Register new user | β |
| POST | /login |
Login user | β |
| POST | /logout |
Logout user | β |
| POST | /auth/google |
Google OAuth login | β |
| POST | /send-otp |
Send OTP for password reset | β |
| POST | /verify-otp |
Verify OTP for password reset | β |
| POST | /reset-password |
Reset password using OTP | β |
| GET | /profile |
Get user profile | β |
| PUT | /profile |
Update user profile | β |
| DELETE | /profile |
Delete user profile | β |
Note: Some endpoints like email verification may be implemented in
utils/verification.js.
git clone https://github.com/yourusername/auth-service.git
cd auth-service
npm installCopy .env.example to .env and fill in your values.
npm startThe service will run on http://localhost:4000 by default.
docker-compose up --buildThis will start both the auth service and a MongoDB instance.
docker-compose downPOST /api/v1/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"username": "johnny",
"password": "yourpassword"
}POST /api/v1/login
Content-Type: application/json
{
"emailOrUsername": "john@example.com",
"password": "yourpassword"
}POST /api/v1/send-otp
Content-Type: application/json
{
"email": "john@example.com"
}POST /api/v1/reset-password
Content-Type: application/json
{
"email": "john@example.com",
"otp": "123456",
"password": "newpassword"
}- Passwords are hashed using bcrypt before storage.
- JWT tokens are signed with a secret and sent as HTTP-only cookies.
- OTPs for password reset are time-limited and stored securely.
- CORS is configured to allow requests from the frontend URL.
- Sensitive configuration is managed via environment variables.
- Add more social login providers (Facebook, GitHub, etc.)
- Implement rate limiting for brute-force protection.
- Add email verification flow (see
utils/verification.js). - Integrate with a user management dashboard.
- Fork the repo
- Create your feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/your-feature) - Open a pull request
This project is licensed under the ISC License.
For questions, contact your-email@example.com.
- src/app.js - Main Express app
- src/routes/auth.routes.js - Route definitions
- src/controllers/auth.controller.js - Controller logic
- src/models/user.model.js - User schema
- src/utils/email.js - Email sending utility
- src/utils/token.js - JWT utilities
- src/utils/verification.js - Email verification utilities
Happy Coding!