feat(rbac): add roles and permissions

This commit is contained in:
Schubert Ferenc 2026-07-02 23:05:59 +02:00
parent 86a32a942c
commit 694b7bd09a
37 changed files with 2682 additions and 218 deletions

View file

@ -0,0 +1,30 @@
"use client";
import type { ReactNode } from "react";
import { hasAllPermissions, hasAnyPermission, hasPermission } from "@/lib/permissions";
import type { CurrentUser, PermissionName } from "@/types/rbac";
type Props = {
user: CurrentUser | null;
permission?: PermissionName;
any?: PermissionName[];
all?: PermissionName[];
children: ReactNode;
};
export default function Can({ user, permission, any, all, children }: Props) {
if (permission && !hasPermission(user, permission)) {
return null;
}
if (any && !hasAnyPermission(user, any)) {
return null;
}
if (all && !hasAllPermissions(user, all)) {
return null;
}
return <>{children}</>;
}