Files
cartsnitch-fork-test/src/components/ProtectedRoute.tsx
T
2026-04-14 15:37:24 +00:00

21 lines
528 B
TypeScript

import { Navigate, Outlet } from 'react-router-dom'
import { authClient } from '../lib/auth-client.ts'
export function ProtectedRoute() {
const { data: session, isPending } = authClient.useSession()
if (isPending) {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-2 border-brand-blue border-t-transparent" />
</div>
)
}
if (!session) {
return <Navigate to="/login" replace />
}
return <Outlet />
}