Fix demo mode showing real user data after logout

React Query cache was shared between /app (real API) and /demo/app
(mock data) because query keys were identical. After login→logout→demo,
stale real data served from cache.

Two fixes:
1. Clear React Query cache on logout (auth store)
2. Namespace all query keys with basePath prefix so /app and /demo/app
   caches are completely isolated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-03-04 20:35:49 -06:00
parent 44993ae601
commit bd9b0ffb34
13 changed files with 263 additions and 70 deletions
+3 -2
View File
@@ -1,13 +1,14 @@
"use client";
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useDataProvider } from '@/lib/demo/data-provider-context';
import { useDataProvider, useQueryKeyPrefix } from '@/lib/demo/data-provider-context';
import { useRouter } from 'next/navigation';
export function useCurrentUser() {
const { auth } = useDataProvider();
const qk = useQueryKeyPrefix();
return useQuery({
queryKey: ['auth', 'user'],
queryKey: qk('auth', 'user'),
queryFn: () => auth.getCurrentUser(),
retry: false,
staleTime: 5 * 60 * 1000, // 5 minutes