mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-20 20:39:10 +00:00
git-subtree-dir: packages/browseros-agent git-subtree-mainline:8f148d0918git-subtree-split:90bd4be300
28 lines
726 B
TypeScript
28 lines
726 B
TypeScript
import { Loader2 } from 'lucide-react'
|
|
import type { FC, ReactNode } from 'react'
|
|
import { Navigate, useLocation } from 'react-router'
|
|
import { useSession } from '@/lib/auth/auth-client'
|
|
|
|
interface AuthGuardProps {
|
|
children: ReactNode
|
|
}
|
|
|
|
export const AuthGuard: FC<AuthGuardProps> = ({ children }) => {
|
|
const { data: session, isPending } = useSession()
|
|
const location = useLocation()
|
|
|
|
if (isPending) {
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-background">
|
|
<Loader2 className="size-8 animate-spin text-muted-foreground" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!session) {
|
|
return <Navigate to="/login" state={{ from: location }} replace />
|
|
}
|
|
|
|
return <>{children}</>
|
|
}
|