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() } /**