Imporve UI and token

This commit is contained in:
Urtzi Alfaro
2026-01-11 07:50:34 +01:00
parent bf1db7cb9e
commit 5533198cab
14 changed files with 1370 additions and 670 deletions

View File

@@ -200,9 +200,9 @@ export const useAuthStore = create<AuthState>()(
}
set({ isLoading: true });
const response = await authService.refreshToken(refreshToken);
if (response && response.access_token) {
// Set the auth tokens on the API client immediately
apiClient.setAuthToken(response.access_token);
@@ -231,14 +231,15 @@ export const useAuthStore = create<AuthState>()(
throw new Error('Token refresh failed');
}
} catch (error) {
// CRITICAL: Only reset isLoading, don't log out the user
// The user's session is still valid even if token refresh fails
// They can continue using the app with their current token
set({
user: null,
token: null,
refreshToken: null,
isAuthenticated: false,
isLoading: false,
error: error instanceof Error ? error.message : 'Error al renovar sesión',
});
console.error('Token refresh failed but keeping user logged in:', error);
throw error;
}
},
@@ -337,6 +338,10 @@ export const useAuthStore = create<AuthState>()(
token: state.token,
refreshToken: state.refreshToken,
isAuthenticated: state.isAuthenticated,
// CRITICAL: Persist JWT subscription data for UI consistency
jwtSubscription: state.jwtSubscription,
jwtTenantAccess: state.jwtTenantAccess,
primaryTenantId: state.primaryTenantId,
}),
onRehydrateStorage: () => (state) => {
// Initialize API client with stored tokens when store rehydrates