From b47da20b7f27c8010ba6a6f10767369329ad3aef Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Mon, 2 Feb 2026 11:19:31 -0600 Subject: [PATCH] Fix stale hasStarterDeck causing redirect to /starter - Always fetch user profile during app init to get fresh hasStarterDeck status - Verify with API when local state shows no starter (handles stale localStorage data) - Clear starter status cache when user data is set --- frontend/src/composables/useAuth.ts | 5 +++-- frontend/src/router/guards.ts | 6 +++++- frontend/src/stores/auth.ts | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/composables/useAuth.ts b/frontend/src/composables/useAuth.ts index efd06c0..8b2162e 100644 --- a/frontend/src/composables/useAuth.ts +++ b/frontend/src/composables/useAuth.ts @@ -307,8 +307,9 @@ export function useAuth() { // First, let the store validate/refresh tokens await authStore.init() - // If we have tokens but no user data, fetch the profile - if (authStore.isAuthenticated && !authStore.user) { + // If we have tokens, fetch user profile to get hasStarterDeck status + // This must be done here, not in the router guard, to avoid race conditions + if (authStore.isAuthenticated) { try { const profileResponse = await apiClient.get('/api/users/me') const user = transformUserProfile(profileResponse) diff --git a/frontend/src/router/guards.ts b/frontend/src/router/guards.ts index 5463e8b..bb2397c 100644 --- a/frontend/src/router/guards.ts +++ b/frontend/src/router/guards.ts @@ -183,7 +183,11 @@ export async function checkStarter( // Check if user data is available with hasStarterDeck flag if (auth.user) { if (!auth.user.hasStarterDeck) { - return { path: '/starter' } + // Local state says no starter - verify with API to handle stale data + const hasStarter = await fetchStarterStatus(auth.user.id) + if (!hasStarter) { + return { path: '/starter' } + } } return undefined } diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index de35e26..eb4d380 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -57,6 +57,8 @@ export const useAuthStore = defineStore('auth', () => { */ function setUser(userData: User): void { user.value = userData + // Clear cached starter status since we just fetched fresh user data + clearStarterStatusCache() } /**