From e34d5149efea239b2da8efab25ab614349b0c097 Mon Sep 17 00:00:00 2001 From: tankgxy Date: Sun, 14 Jun 2026 00:43:09 +0800 Subject: [PATCH 1/2] Fix: skip username uniqueness check on partial profile updates --- src/app/api/profile/route.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/api/profile/route.ts b/src/app/api/profile/route.ts index 945cc634..e7b030c4 100644 --- a/src/app/api/profile/route.ts +++ b/src/app/api/profile/route.ts @@ -79,18 +79,20 @@ export async function PUT(request: NextRequest) { } // Check if username is taken by another user - const { data: existingUser } = await supabase - .from("profiles") - .select("id") - .eq("username", validationResult.data.username) - .neq("id", user.id) - .single(); - - if (existingUser) { - return NextResponse.json( - { error: "Username is already taken" }, - { status: 400 } - ); + if (validationResult.data.username) { + const { data: existingUser } = await supabase + .from("profiles") + .select("id") + .eq("username", validationResult.data.username) + .neq("id", user.id) + .maybeSingle(); + + if (existingUser) { + return NextResponse.json( + { error: "Username is already taken" }, + { status: 400 } + ); + } } // Get current profile to check for resume changes From a5b2be2ec81ac250cff18f9142dd2a70b8fe7eb0 Mon Sep 17 00:00:00 2001 From: tankgxy Date: Sun, 14 Jun 2026 01:04:07 +0800 Subject: [PATCH 2/2] fix: make username optional in profileSchema for partial PATCH updates --- src/lib/validations.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/validations.ts b/src/lib/validations.ts index 9b06b8f8..4308caea 100644 --- a/src/lib/validations.ts +++ b/src/lib/validations.ts @@ -80,7 +80,8 @@ export const profileSchema = z.object({ .regex( /^[a-zA-Z0-9_-]+$/, "Username can only contain letters, numbers, underscores, and hyphens" - ), + ) + .optional(), full_name: z.string().max(100).optional().nullable(), bio: z.string().max(1000).optional().nullable(), skills: z.array(z.string()).max(20).default([]),