fix: recover missing profile rows on save
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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\(/);
|
||||
});
|
||||
Reference in New Issue
Block a user