Skip to content

Commit e3a3dfc

Browse files
Yushin-Lclaude
andcommitted
Fix admin user approval: remove .single() and add RLS note
Supabase returns 0 rows when RLS blocks the update result. Removed .select().single() from approve/revoke/role change APIs. Admin needs RLS policy to update other users' profiles. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e9cf14e commit e3a3dfc

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

src/lib/admin/api.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,34 @@ export async function getAllProfiles(): Promise<Profile[]> {
2525
return (data as Profile[]) ?? [];
2626
}
2727

28-
export async function approveUser(userId: string): Promise<Profile> {
29-
const { data, error } = await supabase
28+
export async function approveUser(userId: string): Promise<void> {
29+
const { error } = await supabase
3030
.from("profiles")
3131
.update({ is_approved: true })
32-
.eq("id", userId)
33-
.select()
34-
.single();
32+
.eq("id", userId);
3533

3634
if (error) throw error;
37-
return data as Profile;
3835
}
3936

40-
export async function revokeUser(userId: string): Promise<Profile> {
41-
const { data, error } = await supabase
37+
export async function revokeUser(userId: string): Promise<void> {
38+
const { error } = await supabase
4239
.from("profiles")
4340
.update({ is_approved: false })
44-
.eq("id", userId)
45-
.select()
46-
.single();
41+
.eq("id", userId);
4742

4843
if (error) throw error;
49-
return data as Profile;
5044
}
5145

5246
export async function updateUserRole(
5347
userId: string,
5448
role: Profile["role"]
55-
): Promise<Profile> {
56-
const { data, error } = await supabase
49+
): Promise<void> {
50+
const { error } = await supabase
5751
.from("profiles")
5852
.update({ role })
59-
.eq("id", userId)
60-
.select()
61-
.single();
53+
.eq("id", userId);
6254

6355
if (error) throw error;
64-
return data as Profile;
6556
}
6657

6758
// ---- Comments ----

0 commit comments

Comments
 (0)