From 43f0ef5ac1b09b85203f9d50f49c4bb56a1593be Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Mon, 17 Nov 2025 02:50:21 +0000 Subject: [PATCH] completionId: cgen-f397a58d211b4147ab5db5a0646acafb cgen-f397a58d211b4147ab5db5a0646acafb --- api/creators.ts | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/api/creators.ts b/api/creators.ts index 28376a4f..20d918f2 100644 --- a/api/creators.ts +++ b/api/creators.ts @@ -131,11 +131,49 @@ export async function createCreatorProfile(req: Request, userId: string) { spotify_profile_url, } = body; + // Validate required fields + if (!username || typeof username !== "string" || username.trim().length === 0) { + return new Response( + JSON.stringify({ error: "Username is required and must be a non-empty string" }), + { status: 400, headers: { "Content-Type": "application/json" } }, + ); + } + + if (!experience_level) { + return new Response( + JSON.stringify({ error: "Experience level is required" }), + { status: 400, headers: { "Content-Type": "application/json" } }, + ); + } + + if (!primary_arm) { + return new Response( + JSON.stringify({ error: "Primary arm is required" }), + { status: 400, headers: { "Content-Type": "application/json" } }, + ); + } + + const normalizedUsername = username.trim().toLowerCase(); + + // Check if username already exists + const { data: existingCreator } = await supabase + .from("aethex_creators") + .select("id") + .eq("username", normalizedUsername) + .single(); + + if (existingCreator) { + return new Response( + JSON.stringify({ error: "Username is already taken" }), + { status: 409, headers: { "Content-Type": "application/json" } }, + ); + } + const { data, error } = await supabase .from("aethex_creators") .insert({ user_id: userId, - username, + username: normalizedUsername, bio, skills: skills || [], avatar_url,