1
0
forked from baron/baron-sso

feat: optimize tenant admin view and enhance user list with dynamic columns and metadata search

This commit is contained in:
2026-03-04 13:32:01 +09:00
parent 02acdf835f
commit d1c3bba3e0
8 changed files with 206 additions and 67 deletions

View File

@@ -0,0 +1,36 @@
import * as React from "react";
import { useQuery } from "@tanstack/react-query";
import { fetchMe } from "../../lib/adminApi";
interface RoleGuardProps {
children: React.ReactNode;
roles: string[];
fallback?: React.ReactNode;
}
/**
* RoleGuard conditionally renders children based on the current user's role.
*
* Usage:
* <RoleGuard roles={['super_admin']}>
* <button>System Only Action</button>
* </RoleGuard>
*/
export function RoleGuard({ children, roles, fallback = null }: RoleGuardProps) {
const { data: profile, isLoading } = useQuery({
queryKey: ["me"],
queryFn: fetchMe,
staleTime: 5 * 60 * 1000, // 5 minutes
});
if (isLoading) return null;
const userRole = profile?.role || "user";
const hasAccess = roles.includes(userRole);
if (!hasAccess) {
return <>{fallback}</>;
}
return <>{children}</>;
}