From b220807d70f70180e74054bf1451a88c3216dce7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Jul 2026 23:04:54 -0400 Subject: [PATCH] Fix dashboard auth image preload and API base resolution --- apps/dashboard/src/app/(dashboard)/reports/page.tsx | 4 ++-- .../forgot-password/ForgotPasswordPageClient.tsx | 8 ++++---- .../app/reset-password/ResetPasswordPageClient.tsx | 4 ++-- .../app/sign-in/[[...sign-in]]/SignInPageClient.tsx | 13 +++++++------ .../src/app/sign-up/[[...sign-up]]/SignUpForm.tsx | 2 -- apps/dashboard/src/app/verify-email/page.tsx | 5 ++--- .../src/components/layout/PublicHeader.tsx | 1 - 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/apps/dashboard/src/app/(dashboard)/reports/page.tsx b/apps/dashboard/src/app/(dashboard)/reports/page.tsx index 714e3bb..59eb49d 100644 --- a/apps/dashboard/src/app/(dashboard)/reports/page.tsx +++ b/apps/dashboard/src/app/(dashboard)/reports/page.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react' import { formatCurrency } from '@rentaldrivego/types' -import { API_BASE, apiFetch } from '@/lib/api' +import { apiFetch, resolveApiBase } from '@/lib/api' import { useDashboardI18n } from '@/components/I18nProvider' interface ReportRow { @@ -110,7 +110,7 @@ export default function ReportsPage() { setExporting(true) setError(null) try { - const res = await fetch(`${API_BASE}/analytics/report?period=${period}&format=CSV`, { + const res = await fetch(`${resolveApiBase()}/analytics/report?period=${period}&format=CSV`, { credentials: 'include', }) if (!res.ok) { diff --git a/apps/dashboard/src/app/forgot-password/ForgotPasswordPageClient.tsx b/apps/dashboard/src/app/forgot-password/ForgotPasswordPageClient.tsx index 7838057..14240e0 100644 --- a/apps/dashboard/src/app/forgot-password/ForgotPasswordPageClient.tsx +++ b/apps/dashboard/src/app/forgot-password/ForgotPasswordPageClient.tsx @@ -5,7 +5,7 @@ import Link from "next/link"; import { useState } from "react"; import { useDashboardI18n } from "@/components/I18nProvider"; import PublicShell from "@/components/layout/PublicShell"; -import { API_BASE } from "@/lib/api"; +import { resolveApiBase } from "@/lib/api"; import { carplaceUrl } from "@/lib/urls"; const DASHBOARD_LOGO_SRC = "/dashboard/rentaldrivego.png"; @@ -69,14 +69,15 @@ export default function ForgotPasswordPageClient({ setLoading(true); setError(null); try { + const apiBase = resolveApiBase(); // Try employee first, then admin — mirrors the sign-in page which handles both const [empRes, adminRes] = await Promise.all([ - fetch(`${API_BASE}/auth/employee/forgot-password`, { + fetch(`${apiBase}/auth/employee/forgot-password`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }), }), - fetch(`${API_BASE}/admin/auth/forgot-password`, { + fetch(`${apiBase}/admin/auth/forgot-password`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }), @@ -103,7 +104,6 @@ export default function ForgotPasswordPageClient({ alt="RentalDriveGo" width={104} height={104} - priority unoptimized className="h-24 w-24 rounded-[1.75rem] border border-stone-200 bg-white p-1.5 shadow-sm transition-colors dark:border-blue-800 dark:bg-blue-950" /> diff --git a/apps/dashboard/src/app/reset-password/ResetPasswordPageClient.tsx b/apps/dashboard/src/app/reset-password/ResetPasswordPageClient.tsx index 68a91c0..915bf34 100644 --- a/apps/dashboard/src/app/reset-password/ResetPasswordPageClient.tsx +++ b/apps/dashboard/src/app/reset-password/ResetPasswordPageClient.tsx @@ -5,7 +5,7 @@ import { Suspense, useState } from 'react' import { useSearchParams } from 'next/navigation' import { useDashboardI18n } from '@/components/I18nProvider' import PublicShell from '@/components/layout/PublicShell' -import { API_BASE } from '@/lib/api' +import { resolveApiBase } from '@/lib/api' export default function ResetPasswordPageClient({ embedded = false }: { embedded?: boolean }) { return ( @@ -92,7 +92,7 @@ function ResetPasswordContent({ embedded = false }: { embedded?: boolean }) { setLoading(true) setError(null) try { - const res = await fetch(`${API_BASE}/auth/employee/reset-password`, { + const res = await fetch(`${resolveApiBase()}/auth/employee/reset-password`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, password }), diff --git a/apps/dashboard/src/app/sign-in/[[...sign-in]]/SignInPageClient.tsx b/apps/dashboard/src/app/sign-in/[[...sign-in]]/SignInPageClient.tsx index d507228..cf923f8 100644 --- a/apps/dashboard/src/app/sign-in/[[...sign-in]]/SignInPageClient.tsx +++ b/apps/dashboard/src/app/sign-in/[[...sign-in]]/SignInPageClient.tsx @@ -7,7 +7,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useDashboardI18n } from "@/components/I18nProvider"; import PublicShell from "@/components/layout/PublicShell"; import { adminUrl, websiteUrl } from "@/lib/urls"; -import { API_BASE, EMPLOYEE_PROFILE_KEY } from "@/lib/api"; +import { EMPLOYEE_PROFILE_KEY, resolveApiBase } from "@/lib/api"; import { toPublicDashboardPath } from "@/lib/dashboardPaths"; const DASHBOARD_LOGO_SRC = "/dashboard/rentaldrivego.png"; @@ -195,7 +195,6 @@ export default function SignInPageClient({ alt="RentalDriveGo" width={104} height={104} - priority unoptimized className="h-24 w-24 rounded-[1.75rem] border border-stone-200/80 bg-white/85 p-1.5 shadow-sm transition-colors dark:border-blue-800 dark:bg-blue-950/80" /> @@ -279,8 +278,10 @@ function LocalSignInForm({ setCanResendVerification(false); try { + const apiBase = resolveApiBase(); + const tryAdminLogin = async () => { - const adminRes = await fetch(`${API_BASE}/admin/auth/login`, { + const adminRes = await fetch(`${apiBase}/admin/auth/login`, { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", @@ -307,7 +308,7 @@ function LocalSignInForm({ }; const tryEmployeeLogin = async () => { - const empRes = await fetch(`${API_BASE}/auth/employee/login`, { + const empRes = await fetch(`${apiBase}/auth/employee/login`, { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", @@ -379,7 +380,7 @@ function LocalSignInForm({ setError(null); try { - const res = await fetch(`${API_BASE}/auth/employee/resend-verification`, { + const res = await fetch(`${resolveApiBase()}/auth/employee/resend-verification`, { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", @@ -409,7 +410,7 @@ function LocalSignInForm({ ? { totpCode: normalizedCode } : { recoveryCode: normalizedCode }; - const adminRes = await fetch(`${API_BASE}/admin/auth/login`, { + const adminRes = await fetch(`${resolveApiBase()}/admin/auth/login`, { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", diff --git a/apps/dashboard/src/app/sign-up/[[...sign-up]]/SignUpForm.tsx b/apps/dashboard/src/app/sign-up/[[...sign-up]]/SignUpForm.tsx index b44cd93..d36cb4d 100644 --- a/apps/dashboard/src/app/sign-up/[[...sign-up]]/SignUpForm.tsx +++ b/apps/dashboard/src/app/sign-up/[[...sign-up]]/SignUpForm.tsx @@ -249,7 +249,6 @@ export default function SignUpForm({ alt="RentalDriveGo" width={104} height={104} - priority unoptimized className="h-24 w-24 rounded-[1.75rem] border border-stone-200/80 bg-white/85 p-1.5 shadow-sm transition-colors dark:border-blue-800 dark:bg-blue-950/80" /> @@ -287,7 +286,6 @@ export default function SignUpForm({ alt="RentalDriveGo" width={104} height={104} - priority unoptimized className="h-24 w-24 rounded-[1.75rem] border border-stone-200/80 bg-white/85 p-1.5 shadow-sm transition-colors dark:border-blue-800 dark:bg-blue-950/80" /> diff --git a/apps/dashboard/src/app/verify-email/page.tsx b/apps/dashboard/src/app/verify-email/page.tsx index 99f7912..9e67fa0 100644 --- a/apps/dashboard/src/app/verify-email/page.tsx +++ b/apps/dashboard/src/app/verify-email/page.tsx @@ -5,7 +5,7 @@ import { useSearchParams } from 'next/navigation' import Image from 'next/image' import PublicShell from '@/components/layout/PublicShell' import { useDashboardI18n } from '@/components/I18nProvider' -import { API_BASE } from '@/lib/api' +import { resolveApiBase } from '@/lib/api' export default function VerifyEmailPage() { const { language } = useDashboardI18n() @@ -45,7 +45,7 @@ export default function VerifyEmailPage() { async function verify() { try { - const url = `${API_BASE}/auth/employee/verify-email` + const url = `${resolveApiBase()}/auth/employee/verify-email` const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -93,7 +93,6 @@ export default function VerifyEmailPage() { alt="RentalDriveGo" width={80} height={80} - priority unoptimized className="h-20 w-20 rounded-[1.5rem] border border-stone-200/80 bg-white/85 p-1.5 shadow-sm dark:border-blue-800 dark:bg-blue-950/80" /> diff --git a/apps/dashboard/src/components/layout/PublicHeader.tsx b/apps/dashboard/src/components/layout/PublicHeader.tsx index 520e761..a718afb 100644 --- a/apps/dashboard/src/components/layout/PublicHeader.tsx +++ b/apps/dashboard/src/components/layout/PublicHeader.tsx @@ -102,7 +102,6 @@ export default function PublicHeader({ alt="RentalDriveGo" width={36} height={36} - priority unoptimized className="h-8 w-8 rounded-md object-contain sm:h-9 sm:w-9" />