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 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 19:17:50 +03:30
co-authored by Claude Opus 4.8
parent 96b1684b82
commit cec6b51f23
2 changed files with 10 additions and 5 deletions
+7 -3
View File
@@ -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}` } }
);
}
+3 -2
View File
@@ -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,