A full-stack user management application with authentication, two-factor authentication, and a modern React UI.
- π Secure Authentication: JWT-based login system
- π‘οΈ Two-Factor Authentication: TOTP support with QR codes
- π₯ User Management: Full CRUD operations for users
- π Dashboard: Overview statistics and recent user activity
- π¨ Modern UI: Material-UI based React frontend
- ποΈ Database: MongoDB with Mongoose ODM
- π Security: Password hashing, input validation, protected routes
- Node.js + Express.js
- MongoDB + Mongoose
- JWT Authentication
- bcrypt for password hashing
- Speakeasy for 2FA
- QRCode generation
- React 18
- Material-UI (MUI)
- React Router for navigation
- Axios for API calls
- DataGrid for user management
- Node.js (v16 or higher)
- MongoDB running locally or MongoDB Atlas account
- npm or yarn package manager
git clone <your-repo-url>
cd users
npm install
cd frontend
npm install
cd ..Create a .env file in the root directory:
PORT=3001
MONGODB_URI=mongodb://localhost:27017/users
SECRET_KEY=your-super-secret-jwt-key-change-this-in-production
FRONTEND_URL=http://localhost:3000
ADMIN_RESET_TOKEN=admin-super-secret-token-change-in-productionImportant: Change the SECRET_KEY to a secure random string in production.
Make sure MongoDB is running locally, or update the MONGODB_URI to point to your MongoDB instance.
npm run devBackend (Terminal 1):
npm startFrontend (Terminal 2):
cd frontend
npm startThe application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
POST /v1/signup- Basic user registrationPOST /v1/signup-with-2fa- User registration with automatic 2FA setupPOST /v1/verify-signup-2fa- Verify 2FA during signup processPOST /v1/login- User login (returns temp token if 2FA required)POST /v1/complete-login-2fa- Complete login with 2FA verificationPOST /v1/change-password- Change password with old passwordPOST /v1/reset-password- Reset password with or without old passwordPOST /v1/admin-reset-password- Admin password reset (no old password required)POST /v1/generate-reset-token- Generate password reset tokenPOST /v1/reset-password-with-token- Reset password using reset tokenPOST /v1/setup-two-factor- Enable 2FAPOST /v1/verify-two-factor- Verify 2FA tokenPOST /v1/disable-two-factor- Disable 2FA
GET /v1/users- List all usersGET /v1/users/:id- Get specific userPOST /v1/users- Create new userPUT /v1/users/:id- Update userPATCH /v1/users/:id- Partial user updateDELETE /v1/users/:id- Delete user
- New Users: Navigate to http://localhost:3000/signup to create an account
- Existing Users: Navigate to http://localhost:3000/login to sign in
- Gmail Integration: Use the Gmail button to generate a Gmail-style email address
- Two-Factor Setup: Automatically configured during signup process
- View system statistics
- See recent user activity
- Quick overview of user counts and 2FA status
- View Users: See all users in a searchable data grid
- Add User: Click "Add User" to create new accounts
- Edit User: Click the edit icon to modify user details
- Delete User: Click the delete icon to remove users
- Search: Use the search bar to find specific users
- With Old Password: Traditional password change requiring current password
- With Reset Token: Generate a secure token and reset password without old password
- Admin Reset: Administrators can reset any user's password using admin token
- Multiple Methods: Choose the most appropriate reset method for your situation
- Automatic Setup: 2FA is configured during signup process
- QR Code Generation: Scan with Google Authenticator, Authy, etc.
- Manual Setup: Existing users can enable/disable 2FA from dashboard
- Enhanced Security: TOTP-based authentication with 6-digit codes
- Multiple Apps: Support for all major authenticator applications
users/
βββ app/
β βββ controllers/ # API controllers
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # React contexts
β β βββ App.js # Main app component
βββ middleware/ # Express middleware
βββ models/ # Mongoose models
βββ routes/ # API routes
βββ main.js # Express server
βββ package.json
- Password Requirements: Minimum 8 characters with uppercase, lowercase, number, and special character
- JWT Tokens: Secure authentication with expiration
- Password Hashing: bcrypt with salt rounds
- Input Validation: Email format and data sanitization
- Protected Routes: All user operations require authentication
- CORS Configuration: Proper cross-origin resource sharing
npm start- Start backend servernpm run dev- Start both backend and frontendnpm run build- Build frontend for productionnpm run install-frontend- Install frontend dependencies
- Backend: Add routes in
routes/directory, controllers inapp/controllers/ - Frontend: Add components in
frontend/src/components/, update routing inApp.js
- MongoDB Connection Error: Ensure MongoDB is running and the connection string is correct
- Port Already in Use: Change the PORT in
.envfile - Frontend Build Errors: Clear
node_modulesand reinstall dependencies - Authentication Issues: Check JWT token expiration and secret key configuration
- Backend logs appear in the terminal running
npm start - Frontend logs appear in the browser console and terminal
- Set
NODE_ENV=production - Use a strong, unique
SECRET_KEY - Configure MongoDB Atlas or production MongoDB instance
- Set up proper CORS origins
- Use environment variables for all sensitive configuration
- Build frontend with
npm run build - Serve static files from Express or use a CDN
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the ISC License.