import { useMutation } from "@tanstack/react-query"; import { CheckCircle2, XCircle } from "lucide-react"; import { useState } from "react"; import { Button } from "../../../components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "../../../components/ui/card"; import { Input } from "../../../components/ui/input"; import { Label } from "../../../components/ui/label"; import apiClient from "../../../lib/apiClient"; import { t } from "../../../lib/i18n"; type CheckPermissionResponse = { allowed: boolean; query: { namespace: string; object: string; relation: string; subject: string; }; }; function PermissionChecker() { const [namespace, setNamespace] = useState("Tenant"); const [object, setObject] = useState(""); const [relation, setRelation] = useState("manage"); const [subject, setSubject] = useState(""); const checkMutation = useMutation({ mutationFn: async () => { const { data } = await apiClient.get( "/v1/admin/debug/check-permission", { params: { namespace, object, relation, subject }, }, ); return data; }, }); const result = checkMutation.data; return ( {t("ui.admin.auth_guard.checker.title", "ReBAC permission checker")} {t( "ui.admin.auth_guard.checker.description", "Check in real time whether a subject has access to a resource through Ory Keto.", )}
setRelation(e.target.value)} />
setObject(e.target.value)} />
setSubject(e.target.value)} />
{checkMutation.isSuccess && result && (
{result.allowed ? ( <>
{t("ui.admin.auth_guard.checker.allowed", "Access ALLOWED")}

{t( "ui.admin.auth_guard.checker.allowed_description", "The subject has access to the requested resource, including inherited permissions.", )}

) : ( <>
{t("ui.admin.auth_guard.checker.denied", "Access DENIED")}

{t( "ui.admin.auth_guard.checker.denied_description", "The subject does not have access to the requested resource.", )}

)}
)}
); } export default PermissionChecker;