diff --git a/apps/backoffice/src/app/features/certificate-designer/config/designer.ts b/apps/backoffice/src/app/features/certificate-designer/config/designer.ts index 07d22cd74..056d2a739 100644 --- a/apps/backoffice/src/app/features/certificate-designer/config/designer.ts +++ b/apps/backoffice/src/app/features/certificate-designer/config/designer.ts @@ -1,9 +1,9 @@ import type { Bilingual, LicenseCategory, LicenseTemplate, LicenseType } from '@ema-platform/api'; +import { BASE_API_URL } from '@ema-platform/api'; + /** Same resolution — and same fallback — the shared RTK Query baseQuery uses. */ -export const API_BASE_URL = - (import.meta as { env?: Record }).env?.['VITE_BASE_API_URL'] ?? - 'http://localhost:3001/api'; +export const API_BASE_URL = BASE_API_URL; export const STATUS_COLOR: Record = { DRAFT: 'gray', diff --git a/apps/backoffice/src/app/features/user-management/UserManagementPage.tsx b/apps/backoffice/src/app/features/user-management/UserManagementPage.tsx index 6a96bba84..20d277399 100644 --- a/apps/backoffice/src/app/features/user-management/UserManagementPage.tsx +++ b/apps/backoffice/src/app/features/user-management/UserManagementPage.tsx @@ -3,6 +3,7 @@ import { useCallback, useEffect, useRef } from 'react'; import { createRoot, type Root } from 'react-dom/client'; import { useNavigate } from 'react-router-dom'; import { UserManagementApp } from '@tria-plc/iamui'; +import { BASE_API_URL } from '@ema-platform/api'; import type { DesignConfig, UserManagementSessionOptions } from '@tria-plc/iamui'; import '@tria-plc/iamui/style.css'; @@ -99,7 +100,7 @@ const UM_CONFIG: DesignConfig = { const UM_RUNTIME = { basename: '/um', - apiUrl: import.meta.env.VITE_BASE_API_URL, + apiUrl: BASE_API_URL, }; const buttonStyle: React.CSSProperties = { diff --git a/apps/portal/src/app/features/certificates/pages/CertificatesPage.tsx b/apps/portal/src/app/features/certificates/pages/CertificatesPage.tsx index edbe6f516..f7cf52743 100644 --- a/apps/portal/src/app/features/certificates/pages/CertificatesPage.tsx +++ b/apps/portal/src/app/features/certificates/pages/CertificatesPage.tsx @@ -120,9 +120,7 @@ function formatDate(value: string | null | undefined): string { }); } -const API_BASE = - (import.meta as { env?: Record }).env?.['VITE_BASE_API_URL'] ?? - 'http://localhost:3001/api'; +import { BASE_API_URL as API_BASE } from '@ema-platform/api'; async function generateCertificate(profileId: string): Promise { const token = authStorage.getToken(); diff --git a/libs/api/src/index.ts b/libs/api/src/index.ts index 903012532..e01bec7dd 100644 --- a/libs/api/src/index.ts +++ b/libs/api/src/index.ts @@ -7,5 +7,5 @@ export * from './lib/features/seafarer'; export * from './lib/features/seafarer-registration'; export * from './lib/features/seafarer-document'; export * from './lib/features/vessel'; -export { baseQueryWithReauth, configureTokenRefresh } from './lib/base-api/base-query-with-reauth'; +export { BASE_API_URL, baseQueryWithReauth, configureTokenRefresh } from './lib/base-api/base-query-with-reauth'; export { openAuthedDocument, downloadAuthedFile } from './lib/base-api/download'; diff --git a/libs/api/src/lib/base-api/base-query-with-reauth.ts b/libs/api/src/lib/base-api/base-query-with-reauth.ts index 6f27c1b4f..8b9feb2cb 100644 --- a/libs/api/src/lib/base-api/base-query-with-reauth.ts +++ b/libs/api/src/lib/base-api/base-query-with-reauth.ts @@ -2,10 +2,15 @@ import { fetchBaseQuery, type BaseQueryFn } from "@reduxjs/toolkit/query/react"; import type { FetchArgs, FetchBaseQueryError } from "@reduxjs/toolkit/query"; import { resolveSessionContext } from "../session"; +/** + * The one place the backend URL is resolved: VITE_BASE_API_URL from the env, + * falling back to the local dev API (3001 — the portal itself owns 3000 for + * the Fayda redirect). Import this; do not re-derive it. + */ export const BASE_API_URL = (import.meta as { env?: Record }).env?.[ "VITE_BASE_API_URL" - ] ?? "http://localhost:3001/api"; + ]?.trim() || "http://localhost:3001/api"; let _onTokenExpired: (() => Promise) | null = null; let _onAuthFailure: (() => void) | null = null; diff --git a/libs/api/src/lib/features/licensing/licensing.helpers.ts b/libs/api/src/lib/features/licensing/licensing.helpers.ts index c74eabbc6..e5833387d 100644 --- a/libs/api/src/lib/features/licensing/licensing.helpers.ts +++ b/libs/api/src/lib/features/licensing/licensing.helpers.ts @@ -10,9 +10,7 @@ import type { ValidationIssue, } from './licensing.types'; -const BASE_API_URL = - (import.meta as { env?: Record }).env?.['VITE_BASE_API_URL'] ?? - 'http://localhost:3001/api'; +import { BASE_API_URL } from '../../base-api/base-query-with-reauth'; /** * Uploads a document straight to the API. diff --git a/libs/auth/src/lib/components/AuthBootstrap.tsx b/libs/auth/src/lib/components/AuthBootstrap.tsx index afabc2988..264738c00 100644 --- a/libs/auth/src/lib/components/AuthBootstrap.tsx +++ b/libs/auth/src/lib/components/AuthBootstrap.tsx @@ -6,9 +6,7 @@ import { hydrateAuth, logout, setToken, setUser } from '../store/auth.slice'; import { refreshAccessToken } from '../utils/refresh-token'; import type { AuthUser } from '../types/auth.types'; -const BASE_API_URL = - (import.meta as { env?: Record }).env?.['VITE_BASE_API_URL'] ?? - 'http://localhost:3001/api'; +import { BASE_API_URL } from '@ema-platform/api'; /** * Restores the signed-in session before the router renders. diff --git a/libs/auth/src/lib/utils/refresh-token.ts b/libs/auth/src/lib/utils/refresh-token.ts index 1d5312593..6ceb275cf 100644 --- a/libs/auth/src/lib/utils/refresh-token.ts +++ b/libs/auth/src/lib/utils/refresh-token.ts @@ -1,9 +1,6 @@ import { authStorage } from "./auth-storage"; -const BASE_API_URL = - (import.meta as { env?: Record }).env?.[ - "VITE_BASE_API_URL" - ] ?? "http://localhost:3001/api"; +import { BASE_API_URL } from "@ema-platform/api"; interface RefreshResponse { token: string;