Resolve merge conflict in authStore.ts - use dynamic import for fetchAPI
This commit is contained in:
@@ -128,7 +128,7 @@ export default function ResourceDebugOverlay({ enabled }: ResourceDebugOverlayPr
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
// Silently handle 404s and other errors - metrics might not exist for all requests
|
||||
// Silently handle 404s and other errors - metrics might not exist for all requests
|
||||
try {
|
||||
const response = await nativeFetch.call(window, `${API_BASE_URL}/v1/system/request-metrics/${requestId}/`, {
|
||||
method: 'GET',
|
||||
@@ -136,6 +136,11 @@ export default function ResourceDebugOverlay({ enabled }: ResourceDebugOverlayPr
|
||||
credentials: 'include', // Include session cookies for authentication
|
||||
});
|
||||
|
||||
// Silently ignore 404s - metrics endpoint might not exist for all requests
|
||||
if (response.status === 404) {
|
||||
return; // Don't log or retry 404s
|
||||
}
|
||||
|
||||
if (response.ok) {
|
||||
const responseData = await response.json();
|
||||
// Extract data from unified API response format: {success: true, data: {...}}
|
||||
|
||||
@@ -153,6 +153,24 @@ export default function Images() {
|
||||
loadImages();
|
||||
}, [loadImages]);
|
||||
|
||||
// Listen for site and sector changes and refresh data
|
||||
useEffect(() => {
|
||||
const handleSiteChange = () => {
|
||||
loadImages();
|
||||
};
|
||||
|
||||
const handleSectorChange = () => {
|
||||
loadImages();
|
||||
};
|
||||
|
||||
window.addEventListener('siteChanged', handleSiteChange);
|
||||
window.addEventListener('sectorChanged', handleSectorChange);
|
||||
return () => {
|
||||
window.removeEventListener('siteChanged', handleSiteChange);
|
||||
window.removeEventListener('sectorChanged', handleSectorChange);
|
||||
};
|
||||
}, [loadImages]);
|
||||
|
||||
// Debounced search
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
@@ -258,7 +276,7 @@ export default function Images() {
|
||||
type: 'in_article',
|
||||
position: img.position || idx + 1,
|
||||
contentTitle: contentImages.content_title || `Content #${contentId}`,
|
||||
prompt: img.prompt,
|
||||
prompt: img.prompt || undefined,
|
||||
status: 'pending',
|
||||
progress: 0,
|
||||
imageUrl: null,
|
||||
|
||||
@@ -193,13 +193,13 @@ export const useAuthStore = create<AuthState>()(
|
||||
}
|
||||
|
||||
try {
|
||||
// Use unified API system - fetchAPI automatically handles auth token from store
|
||||
// Use fetchAPI which handles token automatically and extracts data from unified format
|
||||
// fetchAPI is already imported at the top of the file
|
||||
const response = await fetchAPI('/v1/auth/me/');
|
||||
|
||||
// fetchAPI extracts data from unified format {success: true, data: {user: {...}}}
|
||||
// So response is {user: {...}}
|
||||
|
||||
// fetchAPI extracts data field, so response is {user: {...}}
|
||||
if (!response || !response.user) {
|
||||
throw new Error('Invalid user data received');
|
||||
throw new Error('Failed to refresh user data');
|
||||
}
|
||||
|
||||
// Update user data with latest from server
|
||||
@@ -209,7 +209,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
// If refresh fails, don't logout - just log the error
|
||||
// User might still be authenticated, just couldn't refresh data
|
||||
console.warn('Failed to refresh user data:', error);
|
||||
throw new Error(error.message || 'Failed to refresh user data');
|
||||
// Don't throw - just log the warning to prevent error accumulation
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user