Refactor site building workflow and context handling; update API response structure for improved clarity and consistency. Adjust frontend components to align with new data structure, including error handling and loading states.
This commit is contained in:
@@ -235,8 +235,23 @@ export const useAuthStore = create<AuthState>()(
|
||||
|
||||
set({ user: refreshedUser, isAuthenticated: true });
|
||||
} catch (error: any) {
|
||||
console.warn('Failed to refresh user data:', error);
|
||||
set({ user: null, token: null, refreshToken: null, isAuthenticated: false });
|
||||
// Only logout on authentication/authorization errors, not on network errors
|
||||
// Network errors (500, timeout, etc.) should not log the user out
|
||||
const isAuthError = error?.code === 'ACCOUNT_REQUIRED' ||
|
||||
error?.code === 'PLAN_REQUIRED' ||
|
||||
error?.status === 401 ||
|
||||
error?.status === 403 ||
|
||||
(error?.message && error.message.includes('Not authenticated'));
|
||||
|
||||
if (isAuthError) {
|
||||
// Real authentication error - logout user
|
||||
console.warn('Authentication error during refresh, logging out:', error);
|
||||
set({ user: null, token: null, refreshToken: null, isAuthenticated: false });
|
||||
} else {
|
||||
// Network/server error - don't logout, just throw the error
|
||||
// The caller (AppLayout) will handle it gracefully
|
||||
console.debug('Non-auth error during refresh (will retry):', error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user