fix: handle wrapped permission responses

This commit is contained in:
ShukeBta
2026-05-29 14:11:37 +08:00
parent 7500cf07cb
commit 931db7a242
7 changed files with 84 additions and 43 deletions
+2 -2
View File
@@ -47,13 +47,13 @@ export function Layout() {
}, [location.pathname])
useEffect(() => {
if (user && !isPermissionLoading && Object.keys(permissions).length === 0) {
if (user && !isPermissionLoading && Object.keys(permissions ?? {}).length === 0) {
fetchPermissions().catch(() => undefined)
}
}, [fetchPermissions, isPermissionLoading, permissions, user])
const isAdmin = user?.role === 'admin'
const can = (key: string) => isAdmin || isSuper || permissions[key] === true
const can = (key: string) => isAdmin || isSuper || (permissions ?? {})[key] === true
const handleSearchSubmit = (e: React.FormEvent) => {
e.preventDefault()