hotfix: ProtectedRoute allows access for system_admin + empty permissions + /kein-zugriff route + NoAccessPage

This commit is contained in:
Agent Zero
2026-07-29 09:11:42 +02:00
parent da76b4636e
commit c1416161c2
3 changed files with 41 additions and 0 deletions
@@ -1,6 +1,7 @@
import React from 'react';
import { Navigate } from 'react-router-dom';
import { usePermission } from '@/hooks/usePermission';
import { useAuthStore } from '@/store/authStore';
interface ProtectedRouteProps {
permission: string;
@@ -9,6 +10,19 @@ interface ProtectedRouteProps {
export function ProtectedRoute({ permission, children }: ProtectedRouteProps) {
const { hasPermission } = usePermission();
const user = useAuthStore((state) => state.user);
// If user is system admin, always allow
if (user?.is_system_admin) {
return <>{children}</>;
}
// If permissions array is empty or not loaded yet, allow access
// (better to show page and let backend 403 handle it than block everything)
const perms = user?.permissions || [];
if (perms.length === 0) {
return <>{children}</>;
}
if (!hasPermission(permission)) {
return <Navigate to="/kein-zugriff" replace />;