Archived
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
29 lines
848 B
TypeScript
29 lines
848 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef } from "react";
|
|
import { useRouter, usePathname } from "next/navigation";
|
|
import { apiV2Data } from "@/lib/apiV2";
|
|
|
|
// Checks once per browser session whether first-time setup is needed.
|
|
// If the backend says yes and we're not already on /setup, redirect there.
|
|
export function SetupGuard() {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const checked = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if (checked.current) return;
|
|
if (pathname?.startsWith("/setup")) return;
|
|
checked.current = true;
|
|
|
|
(apiV2Data("get", "/setup/needed") as Promise<{ needsSetup: boolean }>)
|
|
.then((data) => {
|
|
if (data?.needsSetup) {
|
|
router.replace("/setup");
|
|
}
|
|
})
|
|
.catch(() => {/* API down — don't block */});
|
|
}, [pathname, router]);
|
|
|
|
return null;
|
|
} |