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
This commit is contained in:
Cal Corum 2026-02-02 11:19:31 -06:00
parent 8a416c8ace
commit b47da20b7f
3 changed files with 10 additions and 3 deletions

View File

@ -307,8 +307,9 @@ export function useAuth() {
// First, let the store validate/refresh tokens // First, let the store validate/refresh tokens
await authStore.init() await authStore.init()
// If we have tokens but no user data, fetch the profile // If we have tokens, fetch user profile to get hasStarterDeck status
if (authStore.isAuthenticated && !authStore.user) { // This must be done here, not in the router guard, to avoid race conditions
if (authStore.isAuthenticated) {
try { try {
const profileResponse = await apiClient.get<UserProfileResponse>('/api/users/me') const profileResponse = await apiClient.get<UserProfileResponse>('/api/users/me')
const user = transformUserProfile(profileResponse) const user = transformUserProfile(profileResponse)

View File

@ -183,7 +183,11 @@ export async function checkStarter(
// Check if user data is available with hasStarterDeck flag // Check if user data is available with hasStarterDeck flag
if (auth.user) { if (auth.user) {
if (!auth.user.hasStarterDeck) { 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 return undefined
} }

View File

@ -57,6 +57,8 @@ export const useAuthStore = defineStore('auth', () => {
*/ */
function setUser(userData: User): void { function setUser(userData: User): void {
user.value = userData user.value = userData
// Clear cached starter status since we just fetched fresh user data
clearStarterStatusCache()
} }
/** /**