Files
routstr-core/ui/lib/auth/ProtectedRoute.tsx
T
2025-10-21 22:07:47 +02:00

22 lines
648 B
TypeScript

'use client';
import { useEffect } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { ConfigurationService } from '@/lib/api/services/configuration';
export function ProtectedRoute({ children }: { children: React.ReactNode }) {
const router = useRouter();
const pathname = usePathname();
useEffect(() => {
const publicPaths = ['/login', '/_register', '/unauthorized'];
const isPublicPath = publicPaths.some((path) => pathname.startsWith(path));
if (!isPublicPath && !ConfigurationService.isTokenValid()) {
router.push('/login');
}
}, [router, pathname]);
return <>{children}</>;
}