C. User Management & Profile
Tutorial User Management & Profile
1. Backend User Management
1.1 Role Middleware (src/middleware/role.js)
const checkRole = (roles) => {
return (req, res, next) => {
if (!req.user) {
return res.status(401).json({ message: 'Unauthorized' });
}
if (!roles.includes(req.user.role)) {
return res.status(403).json({ message: 'Forbidden' });
}
next();
};
};
module.exports = { checkRole };1.2 User Model (src/models/User.js) - Extend Existing
1.3 User Controller (src/controllers/userController.js)
1.4 User Routes (src/routes/user.routes.js)
2. Frontend Profile Management
2.1 Profile Service (src/services/profile.service.js)
2.2 Profile Component (src/components/profile/ProfileForm.js)
2.3 User Management Components (src/components/admin/UserManagement.js)
2.4 User Service (src/services/user.service.js)
Catatan Implementasi:
Frontend Components yang perlu dibuat:
Profile settings page
Change password form
Avatar upload component
User list table
User edit modal
Role management interface
Backend Features yang perlu ditambahkan:
Password change functionality
Avatar upload handling
User search dan filtering
Pagination untuk user list
Advanced role permissions
Security Considerations:
Validasi input untuk semua forms
Sanitasi data sebelum menyimpan ke database
File upload restrictions
Role-based access control yang ketat
Additional Features untuk diimplementasikan:
User activity logs
Last login tracking
Session management
Email notifications untuk password changes
Two-factor authentication
Untuk testing:
Test CRUD operations untuk users
Verify role-based access
Test profile updates
Validate file uploads
Check error handling
Test form validations
Last updated
Was this helpful?