From 147ebc859d8cd6be5c0018372c1e3b2f18ebcaa2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 7 May 2026 17:01:11 +0000 Subject: [PATCH] Fix race window in user creation and restore FlagSvg safety fallback auth.server.ts: switch generateId to application-generated UUIDs so the ID is known before the insert, then move flagConfig assignment from create.after (a separate UPDATE) to create.before so it lands in the initial INSERT with no race window. FlagSvg.tsx: validate the config with parseFlagConfig before rendering; corrupt or missing data falls back to a neutral gray triband flag rather than silently rendering blank SVG shapes. https://claude.ai/code/session_01T7iTb9YZLuWJFtKV753tdB --- app/components/ui/FlagSvg.tsx | 31 +++++++++++++++++-------------- app/lib/auth.server.ts | 14 ++++++++------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/components/ui/FlagSvg.tsx b/app/components/ui/FlagSvg.tsx index eafa649..75fb263 100644 --- a/app/components/ui/FlagSvg.tsx +++ b/app/components/ui/FlagSvg.tsx @@ -1,5 +1,5 @@ import { cn } from "~/lib/utils"; -import type { FlagConfig } from "~/lib/flag-types"; +import { parseFlagConfig, type FlagConfig } from "~/lib/flag-types"; interface FlagSvgProps { config: FlagConfig; @@ -8,8 +8,11 @@ interface FlagSvgProps { title?: string; } +const FALLBACK_FLAG: FlagConfig = { pattern: "triband-h", colors: ["#9ca3af", "#6b7280", "#4b5563"] }; + export function FlagSvg({ config, size = 48, className, title }: FlagSvgProps) { - const [c0 = "", c1 = "", c2 = ""] = config.colors; + const safeConfig = parseFlagConfig(config) ?? FALLBACK_FLAG; + const [c0, c1, c2] = safeConfig.colors; return ( {title ? {title} : null} - {config.pattern === "triband-h" && ( + {safeConfig.pattern === "triband-h" && ( <> )} - {config.pattern === "triband-v" && ( + {safeConfig.pattern === "triband-v" && ( <> )} - {config.pattern === "diagonal" && ( + {safeConfig.pattern === "diagonal" && ( <> )} - {config.pattern === "nordic-cross" && ( + {safeConfig.pattern === "nordic-cross" && ( <> @@ -51,7 +54,7 @@ export function FlagSvg({ config, size = 48, className, title }: FlagSvgProps) { )} - {config.pattern === "cross" && ( + {safeConfig.pattern === "cross" && ( <> @@ -60,28 +63,28 @@ export function FlagSvg({ config, size = 48, className, title }: FlagSvgProps) { )} - {config.pattern === "canton" && ( + {safeConfig.pattern === "canton" && ( <> )} - {config.pattern === "triangle" && ( + {safeConfig.pattern === "triangle" && ( <> )} - {config.pattern === "chevron" && ( + {safeConfig.pattern === "chevron" && ( <> )} - {config.pattern === "quartered" && ( + {safeConfig.pattern === "quartered" && ( <> @@ -89,21 +92,21 @@ export function FlagSvg({ config, size = 48, className, title }: FlagSvgProps) { )} - {config.pattern === "bordered" && ( + {safeConfig.pattern === "bordered" && ( <> )} - {config.pattern === "circle" && ( + {safeConfig.pattern === "circle" && ( <> )} - {config.pattern === "star" && ( + {safeConfig.pattern === "star" && ( <> { - await db - .update(schema.users) - .set({ flagConfig: generateFlagConfig(user.id) }) - .where(eq(schema.users.id, user.id)); + before: async (data) => { + return { + data: { + ...data, + flagConfig: generateFlagConfig(data.id), + } as typeof data, + }; }, }, update: { @@ -63,7 +65,7 @@ export const auth = betterAuth({ }, advanced: { database: { - generateId: false, + generateId: () => crypto.randomUUID(), }, }, user: {