Chuyển tới nội dung chính

Authentication & Permission

Luồng đăng nhập

Permission System

Hệ thống phân quyền dựa trên 2 cơ chế:

1. Role-based (vai trò)

interface RoutePermission {
allowedRoles?: string[]; // Chỉ roles này được vào
excludeRoles?: string[]; // Roles này bị loại trừ
superadminOnly?: boolean; // Chỉ superadmin
}

Các roles: superadmin, admin, staff

2. Module-based (module đăng ký)

interface RoutePermission {
requiredModule?: string; // Module key BE cấp cho doanh nghiệp
}

Module key do backend cấp theo gói đăng ký (subscription). Ví dụ doanh nghiệp mua gói "Pro" sẽ có modules: products, warehouse, analytics.

Permission check flow

Token Sync

MFEs không quản lý token riêng. Token được đồng bộ từ Container:

// RemoteApp.tsx của mỗi MFE
function RemoteApp() {
useTokenSync(); // Lắng nghe token changes từ Container
// ...
}

Container lưu token vào localStorage với key từ STORAGE_KEYS.token.