From 3e9e10e7574b5d871e064f7396aced893fba87de Mon Sep 17 00:00:00 2001 From: sirpiglr <49359077-sirpiglr@users.noreply.replit.com> Date: Tue, 16 Dec 2025 00:30:09 +0000 Subject: [PATCH] Improve login flow and admin page access reliability Refactor AuthProvider to await session refetch on login success and add a delay to admin page redirect to prevent immediate logout. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 279f1558-c0e3-40e4-8217-be7e9f4c6eca Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 12a0ed24-3282-4c06-bd03-d33c53459821 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/b984cb14-1d19-4944-922b-bc79e821ed35/279f1558-c0e3-40e4-8217-be7e9f4c6eca/nNnFCpK Replit-Helium-Checkpoint-Created: true --- client/src/lib/auth.tsx | 4 ++-- client/src/pages/admin.tsx | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/src/lib/auth.tsx b/client/src/lib/auth.tsx index 1ea6799..7de07f2 100644 --- a/client/src/lib/auth.tsx +++ b/client/src/lib/auth.tsx @@ -43,8 +43,8 @@ export function AuthProvider({ children }: { children: ReactNode }) { } return res.json(); }, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["session"] }); + onSuccess: async () => { + await queryClient.refetchQueries({ queryKey: ["session"] }); }, }); diff --git a/client/src/pages/admin.tsx b/client/src/pages/admin.tsx index 44f4b1c..07502bd 100644 --- a/client/src/pages/admin.tsx +++ b/client/src/pages/admin.tsx @@ -14,9 +14,12 @@ export default function Admin() { const [, setLocation] = useLocation(); useEffect(() => { - if (!authLoading && !isAuthenticated) { - setLocation("/login"); - } + const timer = setTimeout(() => { + if (!authLoading && !isAuthenticated) { + setLocation("/login"); + } + }, 200); + return () => clearTimeout(timer); }, [authLoading, isAuthenticated, setLocation]); const { data: metrics } = useQuery({