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
This commit is contained in:
sirpiglr 2025-12-16 00:30:09 +00:00
parent 1a538a8085
commit 3e9e10e757
2 changed files with 8 additions and 5 deletions

View file

@ -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"] });
},
});

View file

@ -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({