Files
lcbp3/frontend/components/common/can.tsx
admin c05e715e03
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled
251205:1500 debug backend/frontend
2025-12-05 14:52:15 +07:00

28 lines
542 B
TypeScript

"use client";
import { useSession } from "next-auth/react";
import { ReactNode } from "react";
interface CanProps {
permission: string;
children: ReactNode;
}
export function Can({ permission, children }: CanProps) {
const { data: session } = useSession();
if (!session?.user) {
return null;
}
const userRole = session.user.role;
// Simple role-based check
// If the user's role matches the required permission (role), allow access.
if (userRole === permission) {
return <>{children}</>;
}
return null;
}