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:
parent
8a416c8ace
commit
b47da20b7f
@ -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<UserProfileResponse>('/api/users/me')
|
||||
const user = transformUserProfile(profileResponse)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user