Files
BrowserOS/packages/browseros-agent/apps/agent/components/auth/AuthGuard.tsx
Dani Akash 290ee91a8b Add 'packages/browseros-agent/' from commit '90bd4be3008285bf3825aad3702aff98f872671a'
git-subtree-dir: packages/browseros-agent
git-subtree-mainline: 8f148d0918
git-subtree-split: 90bd4be300
2026-03-13 21:22:09 +05:30

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}</>
}