Skip to content
Open
17 changes: 7 additions & 10 deletions frontend/src/components/common/Resource/AuthVisible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ export interface AuthVisibleProps extends React.PropsWithChildren<{}> {
export default function AuthVisible(props: AuthVisibleProps) {
const { item, authVerb, subresource, namespace, onError, onAuthResult, children } = props;

if (!VALID_AUTH_VERBS.includes(authVerb)) {
console.warn(`Invalid authVerb provided: "${authVerb}". Skipping authorization check.`);
return null;
}

const itemClass: KubeObjectClass | null = (item as KubeObject)?._class?.() ?? item;
const itemName = (item as KubeObject)?.getName?.();

// eslint-disable-next-line react-hooks/rules-of-hooks
const { data } = useQuery<any>({
enabled: !!item,
queryKey: [
Comment thread
kashish00208 marked this conversation as resolved.
Expand All @@ -90,19 +84,22 @@ export default function AuthVisible(props: AuthVisibleProps) {
},
});

const visible = data?.status?.allowed ?? false;

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (data) {
onAuthResult?.({
allowed: visible,
reason: data.status?.reason ?? '',
});
Comment thread
kashish00208 marked this conversation as resolved.
Outdated
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data]);
Comment thread
kashish00208 marked this conversation as resolved.

if (!VALID_AUTH_VERBS.includes(authVerb)) {
Comment thread
kashish00208 marked this conversation as resolved.
Outdated
console.warn(`Invalid authVerb provided: "${authVerb}". Skipping authorization check.`);
return null;
}

const visible = data?.status?.allowed ?? false;

if (!visible) {
return null;
}
Expand Down
Loading