mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 11:04:36 +00:00
22 lines
648 B
TypeScript
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}</>;
|
|
}
|