From cec6b51f23bea97ab3782e8c1b72cacf188f6661 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 19:17:50 +0330 Subject: [PATCH] fix(dashboard): fetch profile by real user uuid, not OTP uuid app/dashboard/page.js fetched the profile with the standalone uuid cookie, which still holds the OTP uuid and 404s. Read the user uuid from the userInfo cookie (falling back to the uuid cookie); the backend resolves it and lazy-creates the profile. Also fix buildPatientUser to read the double-nested response (data.data) and the profile's label field. Co-Authored-By: Claude Opus 4.8 --- app/dashboard/page.js | 10 +++++++--- lib/representationAdapters.js | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/dashboard/page.js b/app/dashboard/page.js index 99a222c..f17f92d 100644 --- a/app/dashboard/page.js +++ b/app/dashboard/page.js @@ -6,6 +6,7 @@ import { removeToken } from "@/utils"; import { cookies } from "next/headers"; import { redirect } from "next/navigation"; import { fetchReq } from "@/lib/req"; +import { safeJsonParse } from "@/lib/sanitize"; import { buildPatientUser } from "@/lib/representationAdapters"; export default async function Dashboard({ searchParams }) { @@ -22,11 +23,14 @@ export default async function Dashboard({ searchParams }) { return redirect("/login"); } - const uuid = cookieStore.get("uuid")?.value; + // The userInfo cookie holds the real user uuid; the standalone `uuid` cookie + // may still carry the OTP uuid, which 404s against user-profile. + const userInfo = safeJsonParse(cookieStore.get("userInfo")?.value); + const userUuid = userInfo?.uuid || cookieStore.get("uuid")?.value; let profile = null; - if (uuid) { + if (userUuid) { profile = await fetchReq( - `${process.env.NEXT_PUBLIC_API_URL}/api/v1/user-profile/${uuid}`, + `${process.env.NEXT_PUBLIC_API_URL}/api/v1/user-profile/${userUuid}`, { headers: { Authorization: `Bearer ${token.value}` } } ); } diff --git a/lib/representationAdapters.js b/lib/representationAdapters.js index 4c2d0d1..94435f3 100644 --- a/lib/representationAdapters.js +++ b/lib/representationAdapters.js @@ -52,11 +52,12 @@ export function adaptRepresentationDashboard(dashboard) { } export function buildPatientUser(profile) { - const data = profile?.data ?? profile ?? {}; + // GET /user-profile is double-nested: { data: { data: {...} } } (after fetchReq → response.data) + const data = profile?.data?.data ?? profile?.data ?? profile ?? {}; return { profile: data.avatar ?? "/assets/images/profile-user.png", - name: [data.name, data.family].filter(Boolean).join(" ").trim(), + name: [data.label ?? data.name, data.family].filter(Boolean).join(" ").trim(), phone: data.phone ?? data.mobile ?? "", total_transactions: 0, number_of_turns: 0,