hotfix: ProtectedRoute allows access for system_admin + empty permissions + /kein-zugriff route + NoAccessPage
This commit is contained in:
@@ -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 />;
|
||||
|
||||
Reference in New Issue
Block a user