From 234ef0fea8115c66160ffbb65f35fa232c9e6a54 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 28 Sep 2025 04:14:05 +0000 Subject: [PATCH] debug: improve logging for profile ensure endpoint cgen-e760c158cc8a45009ef1e20a541e7cd6 --- server/index.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/index.ts b/server/index.ts index e0b730e6..d66f7aed 100644 --- a/server/index.ts +++ b/server/index.ts @@ -84,16 +84,26 @@ export function createServer() { app.post("/api/profile/ensure", async (req, res) => { const { id, profile } = req.body || {}; + console.log("[API] /api/profile/ensure called", { id, profile }); if (!id) return res.status(400).json({ error: "missing id" }); try { - const { data, error } = await adminSupabase + const resp = await adminSupabase .from("user_profiles") .upsert({ id, ...profile }, { onConflict: "id" }) - .select() - .single(); - if (error) return res.status(500).json({ error: error.message }); - res.json(data); + .select(); + // Supabase may return { data, error } or throw. Normalize response + const data = (resp as any).data ?? null; + const error = (resp as any).error ?? null; + if (error) { + console.error("[API] /api/profile/ensure supabase error:", error); + return res.status(500).json({ error: error.message || String(error) }); + } + // If data is an array, pick the first + const row = Array.isArray(data) ? data[0] : data; + console.log("[API] /api/profile/ensure success", { row }); + res.json(row || {}); } catch (e: any) { + console.error("[API] /api/profile/ensure exception:", e); res.status(500).json({ error: e?.message || String(e) }); } });