diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 77837df6..2e0b62e1 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -1322,7 +1322,8 @@ export default function Home() { const birthPlace = selectedBirthPlace(nextProfile); const { data, error } = await createBrowserSupabaseClient() .from("profiles") - .update({ + .upsert({ + id: account.user.id, name: nextProfile.name.trim() || null, birth_date: nextProfile.date || null, birth_time: nextProfile.time || null, @@ -1334,8 +1335,7 @@ export default function Home() { longitude: birthPlace?.lon ?? null, timezone_offset: birthPlace?.tz ?? null, updated_at: new Date().toISOString(), - }) - .eq("id", account.user.id) + }, { onConflict: "id" }) .select("id") .maybeSingle(); if (error) throw error; diff --git a/frontend/supabase/migrations/20260718010000_recover_missing_profile_rows.sql b/frontend/supabase/migrations/20260718010000_recover_missing_profile_rows.sql new file mode 100644 index 00000000..ee5ab568 --- /dev/null +++ b/frontend/supabase/migrations/20260718010000_recover_missing_profile_rows.sql @@ -0,0 +1,25 @@ +begin; + +drop policy if exists profiles_insert_own on public.profiles; +create policy profiles_insert_own + on public.profiles + for insert + to authenticated + with check ((select auth.uid()) = id); + +grant insert ( + id, + name, + birth_date, + birth_time, + country_code, + province_code, + city_code, + district_code, + latitude, + longitude, + timezone_offset, + updated_at +) on public.profiles to authenticated; + +commit; diff --git a/frontend/tests/profile-persistence.test.ts b/frontend/tests/profile-persistence.test.ts new file mode 100644 index 00000000..625301e9 --- /dev/null +++ b/frontend/tests/profile-persistence.test.ts @@ -0,0 +1,8 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; + +test("upserts a missing profile when saving account details", () => { + const source = readFileSync(new URL("../src/app/page.tsx", import.meta.url), "utf8"); + assert.match(source, /\.from\("profiles"\)\s*\.upsert\(/); +});