forked from baron/baron-sso
feat: handle multiple manageable tenants for tenant admin
This commit is contained in:
@@ -36,17 +36,20 @@ function TenantListPage() {
|
||||
queryFn: fetchMe,
|
||||
});
|
||||
|
||||
// Redirect tenant_admin to their own tenant
|
||||
// Redirect tenant_admin ONLY if they have exactly one manageable tenant
|
||||
React.useEffect(() => {
|
||||
if (profile?.role === "tenant_admin" && profile?.tenantId) {
|
||||
navigate(`/tenants/${profile.tenantId}`, { replace: true });
|
||||
if (profile?.role === "tenant_admin") {
|
||||
const manageableCount = profile.manageableTenants?.length ?? 0;
|
||||
if (manageableCount === 1 && profile.tenantId) {
|
||||
navigate(`/tenants/${profile.tenantId}`, { replace: true });
|
||||
}
|
||||
}
|
||||
}, [profile, navigate]);
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ["tenants", { limit: 1000, offset: 0 }],
|
||||
queryFn: () => fetchTenants(1000, 0),
|
||||
enabled: profile?.role === "super_admin",
|
||||
enabled: profile?.role === "super_admin" || (profile?.role === "tenant_admin" && (profile.manageableTenants?.length ?? 0) > 1),
|
||||
});
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
|
||||
Reference in New Issue
Block a user