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:

  1. Frontend Components yang perlu dibuat:

    • Profile settings page

    • Change password form

    • Avatar upload component

    • User list table

    • User edit modal

    • Role management interface

  2. Backend Features yang perlu ditambahkan:

    • Password change functionality

    • Avatar upload handling

    • User search dan filtering

    • Pagination untuk user list

    • Advanced role permissions

  3. Security Considerations:

    • Validasi input untuk semua forms

    • Sanitasi data sebelum menyimpan ke database

    • File upload restrictions

    • Role-based access control yang ketat

  4. Additional Features untuk diimplementasikan:

    • User activity logs

    • Last login tracking

    • Session management

    • Email notifications untuk password changes

    • Two-factor authentication

Untuk testing:

  1. Test CRUD operations untuk users

  2. Verify role-based access

  3. Test profile updates

  4. Validate file uploads

  5. Check error handling

  6. Test form validations

Last updated

Was this helpful?