feat: add Unipile webhook callback endpoint to update profile status in Supabase

This commit is contained in:
Marc Klose 2026-04-06 02:50:28 +03:00
parent d283b15341
commit 521deea5ce

View file

@ -17,7 +17,6 @@ export async function POST(request: NextRequest) {
}; };
if (!account_id || !userId) { if (!account_id || !userId) {
console.error("Unipile callback missing account_id or name:", body);
return NextResponse.json( return NextResponse.json(
{ error: "Missing account_id or user identifier" }, { error: "Missing account_id or user identifier" },
{ status: 400 } { status: 400 }
@ -29,18 +28,22 @@ export async function POST(request: NextRequest) {
process.env.SUPABASE_SERVICE_ROLE_KEY! process.env.SUPABASE_SERVICE_ROLE_KEY!
); );
const { error } = await supabase const { data, error } = await supabase
.from("profiles") .from("profiles")
.update({ .update({
unipile_account_id: account_id, unipile_account_id: account_id,
unipile_account_status: status ?? "CONNECTED", unipile_account_status: status ?? "CONNECTED",
}) })
.eq("id", userId); .eq("id", userId)
.select();
if (error) { if (error) {
console.error("Error saving Unipile account_id:", error);
return NextResponse.json({ error: "DB update failed" }, { status: 500 }); return NextResponse.json({ error: "DB update failed" }, { status: 500 });
} }
if (!data || data.length === 0) {
return NextResponse.json({ error: "Profile not found" }, { status: 404 });
}
return NextResponse.json({ ok: true }); return NextResponse.json({ ok: true });
} }