WebUI module split; docs
This commit is contained in:
@@ -3,17 +3,20 @@ import { Navigate } from "react-router-dom";
|
||||
import type { AuthInfo } from "../types";
|
||||
import { isApiError } from "../api/client";
|
||||
import DismissibleAlert from "./DismissibleAlert";
|
||||
import { hasAnyScope } from "../utils/permissions";
|
||||
import { hasAnyScope, hasScope } from "../utils/permissions";
|
||||
|
||||
type PermissionBoundaryProps = {
|
||||
auth: AuthInfo;
|
||||
anyOf: string[];
|
||||
anyOf?: string[];
|
||||
allOf?: string[];
|
||||
fallback: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export function PermissionBoundary({ auth, anyOf, fallback, children }: PermissionBoundaryProps) {
|
||||
return hasAnyScope(auth, anyOf) ? <>{children}</> : <Navigate to={fallback} replace />;
|
||||
export function PermissionBoundary({ auth, anyOf = [], allOf = [], fallback, children }: PermissionBoundaryProps) {
|
||||
if (allOf.length && !allOf.every((scope) => hasScope(auth, scope))) return <Navigate to={fallback} replace />;
|
||||
if (anyOf.length && !hasAnyScope(auth, anyOf)) return <Navigate to={fallback} replace />;
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
type ResourceAccessBoundaryProps = {
|
||||
|
||||
Reference in New Issue
Block a user