From 64be4b9b3f953303d06d95f5cff81e08b4031142 Mon Sep 17 00:00:00 2001 From: tanweer919 Date: Mon, 13 Jul 2026 02:35:13 +0530 Subject: [PATCH] fix(auth): don't redirect from dashboard until SDK boot completes AuthGate redirected to /portal/login whenever status !== authenticated, which during boot (before restore() resolves) dropped a valid session on reload. Gate the redirect on useAppShell().ready so we only bounce once auth has resolved. --- src/components/dashboard/auth-gate.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/dashboard/auth-gate.tsx b/src/components/dashboard/auth-gate.tsx index fb12945..034183b 100644 --- a/src/components/dashboard/auth-gate.tsx +++ b/src/components/dashboard/auth-gate.tsx @@ -2,7 +2,7 @@ import { useEffect } from "react"; import { useRouter } from "next/navigation"; -import { useAuth } from "@abe-kap/appshell-sdk/react"; +import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react"; import { isShellConfigured } from "@/lib/appshell"; /** @@ -14,16 +14,21 @@ import { isShellConfigured } from "@/lib/appshell"; export function AuthGate({ children }: { children: React.ReactNode }) { const router = useRouter(); const { status } = useAuth(); + const { ready } = useAppShell(); const shell = isShellConfigured(); useEffect(() => { - if (shell && status === "unauthenticated") router.replace("/portal/login"); - }, [shell, status, router]); + // Only bounce to login once the SDK has finished booting AND restore() has + // resolved to unauthenticated. Redirecting while boot is still in flight would + // drop a perfectly valid session on reload (the status is transiently not-yet + // "authenticated" during boot). + if (shell && ready && status === "unauthenticated") router.replace("/portal/login"); + }, [shell, ready, status, router]); - if (shell && status !== "authenticated") { + if (shell && (!ready || status !== "authenticated")) { return (
- {status === "loading" ? "Loading your workspace…" : "Redirecting to sign in…"} + {ready && status === "unauthenticated" ? "Redirecting to sign in…" : "Loading your workspace…"}
); }