update not working

export async function PATCH(request: NextRequest) {
const body = (await request.json()) as Partial<
Omit<Profile, "uuid" | "stripeId">
>;

const supabase = supabaseApiClient();
const { data, error } = await supabase.auth.getUser();

if (error) {
return NextResponse.json(error, { status: error.status });
}

const profileUpdate = await db.transaction(async (tx) => {
await setTxAuthUUID(tx, data.user.id);
await setTxAuthedRole(tx);

try {
await tx
.update(profiles)
.set({ ...body })
.where(eq(profiles.uuid, data.user.id));

return true;
} catch (error) {
return false;
}
});

if (profileUpdate) {
return NextResponse.json({}, { status: 201 });
} else {
return NextResponse.json({}, { status: 400 });
}
}
export async function PATCH(request: NextRequest) {
const body = (await request.json()) as Partial<
Omit<Profile, "uuid" | "stripeId">
>;

const supabase = supabaseApiClient();
const { data, error } = await supabase.auth.getUser();

if (error) {
return NextResponse.json(error, { status: error.status });
}

const profileUpdate = await db.transaction(async (tx) => {
await setTxAuthUUID(tx, data.user.id);
await setTxAuthedRole(tx);

try {
await tx
.update(profiles)
.set({ ...body })
.where(eq(profiles.uuid, data.user.id));

return true;
} catch (error) {
return false;
}
});

if (profileUpdate) {
return NextResponse.json({}, { status: 201 });
} else {
return NextResponse.json({}, { status: 400 });
}
}
this is my api endpoint for patching i have test ...body if values are correct and if data.user.id exist everything should be fine and return true but when i check database it doesnt seem to be updated for more context im using NEXTJS + react query
1 Reply
JustKira
JustKiraOP12mo ago
nvm its problem with supabase RLS for some reason blocks api
Want results from more Discord servers?
Add your server