Skip to content

Commit e34d514

Browse files
committed
Fix: skip username uniqueness check on partial profile updates
1 parent c07c805 commit e34d514

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/app/api/profile/route.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,20 @@ export async function PUT(request: NextRequest) {
7979
}
8080

8181
// Check if username is taken by another user
82-
const { data: existingUser } = await supabase
83-
.from("profiles")
84-
.select("id")
85-
.eq("username", validationResult.data.username)
86-
.neq("id", user.id)
87-
.single();
88-
89-
if (existingUser) {
90-
return NextResponse.json(
91-
{ error: "Username is already taken" },
92-
{ status: 400 }
93-
);
82+
if (validationResult.data.username) {
83+
const { data: existingUser } = await supabase
84+
.from("profiles")
85+
.select("id")
86+
.eq("username", validationResult.data.username)
87+
.neq("id", user.id)
88+
.maybeSingle();
89+
90+
if (existingUser) {
91+
return NextResponse.json(
92+
{ error: "Username is already taken" },
93+
{ status: 400 }
94+
);
95+
}
9496
}
9597

9698
// Get current profile to check for resume changes

0 commit comments

Comments
 (0)