From a947e48c492f9e08f923a65a71028120d08cd744 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Jul 2026 15:02:10 -0400 Subject: [PATCH] Fixed the dashboard sidebar redirect issue by making browser-side dashboard API calls always go through the same-origin proxy at /dashboard/api/v1 --- apps/dashboard/src/lib/api.test.ts | 4 ++-- apps/dashboard/src/lib/api.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/src/lib/api.test.ts b/apps/dashboard/src/lib/api.test.ts index cc972f2..6a10d38 100644 --- a/apps/dashboard/src/lib/api.test.ts +++ b/apps/dashboard/src/lib/api.test.ts @@ -39,7 +39,7 @@ describe('dashboard apiFetch', () => { })) }) - it('normalizes a public API origin to the versioned API base', async () => { + it('keeps browser requests on the dashboard proxy even when a public API origin is configured', async () => { installBrowser() process.env.NEXT_PUBLIC_API_URL = 'https://api.rentaldrivego.ma' const fetchMock = vi.fn(async () => ({ @@ -51,7 +51,7 @@ describe('dashboard apiFetch', () => { const { apiFetch } = await import('./api') await apiFetch('/auth/account/start', { method: 'POST', body: JSON.stringify({}) }) - expect(fetchMock).toHaveBeenCalledWith('https://api.rentaldrivego.ma/api/v1/auth/account/start', expect.any(Object)) + expect(fetchMock).toHaveBeenCalledWith('/dashboard/api/v1/auth/account/start', expect.any(Object)) }) it('does not force JSON content type for FormData payloads', async () => { diff --git a/apps/dashboard/src/lib/api.ts b/apps/dashboard/src/lib/api.ts index e0aeda8..3e533f7 100644 --- a/apps/dashboard/src/lib/api.ts +++ b/apps/dashboard/src/lib/api.ts @@ -6,7 +6,7 @@ function normalizeApiBase(value: string): string { export const API_BASE = normalizeApiBase( typeof window === 'undefined' ? (process.env.API_INTERNAL_URL || 'http://localhost:4000/api/v1') - : (process.env.NEXT_PUBLIC_API_URL || '/dashboard/api/v1'), + : '/dashboard/api/v1', ) export const EMPLOYEE_PROFILE_KEY = 'employee_profile'