Spaces:
Running
Running
Download web/src/components/shell/app-gate.tsx from Aynkhn/WorkPilot-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/web/src/components/shell/app-gate.tsx
- Command line
-
hf download hf://spaces/Aynkhn/WorkPilot-AI/web/src/components/shell/app-gate.tsx
-
curl -L -o app-gate.tsx https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/web/src/components/shell/app-gate.tsx
1.48 kB
| "use client"; | |
| import { Loader2Icon } from "lucide-react"; | |
| import { usePathname, useRouter } from "next/navigation"; | |
| import { useEffect, type ReactNode } from "react"; | |
| import { StepUpProvider } from "@/components/inbox/stepup"; | |
| import { AppShell } from "@/components/shell/app-shell"; | |
| import { useAuth } from "@/lib/auth"; | |
| import { useI18n } from "@/lib/i18n"; | |
| /** Everything behind sign-in. Tokens live in memory, so the gate waits for the silent | |
| * refresh (httpOnly cookie) before deciding. */ | |
| export function AppGate({ children }: { children: ReactNode }) { | |
| const { status } = useAuth(); | |
| const { t } = useI18n(); | |
| const router = useRouter(); | |
| const pathname = usePathname(); | |
| useEffect(() => { | |
| if (status === "anonymous") router.replace(`/login?next=${encodeURIComponent(pathname)}`); | |
| }, [status, router, pathname]); | |
| if (status !== "authenticated") return <FullPageLoading label={t("common.loading")} />; | |
| return ( | |
| <StepUpProvider> | |
| <AppShell>{children}</AppShell> | |
| </StepUpProvider> | |
| ); | |
| } | |
| export function FullPageLoading({ label }: { label?: string }) { | |
| const { t } = useI18n(); | |
| return ( | |
| <div className="grid min-h-dvh place-items-center" role="status" aria-live="polite"> | |
| <span className="flex items-center gap-2 text-sm text-muted-foreground"> | |
| <Loader2Icon className="size-4 animate-spin" aria-hidden /> | |
| {label ?? t("common.loading")} | |
| </span> | |
| </div> | |
| ); | |
| } | |