forked from cartsnitch/cartsnitch
121dc5724e
Co-Authored-By: Paperclip <noreply@paperclip.ing>
21 lines
528 B
TypeScript
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 />
|
|
}
|