Hi everyone!
I'm just getting started with programming, and I'm currently trying to integrate RevenueCat with Supabase to control user access based on subscription status.
I created an Edge Function in Supabase that receives the webhook from RevenueCat and tries to extract the app_user_id
from the payload to identify the user and update their data.
The issue is: even though I can see the app_user_id
correctly in the request body, I still get a 400 error saying "user_id not found". 🥲
Since I'm new to all this, there's a good chance I'm missing something simple — I'd really appreciate any help or guidance!
serve(async (req) => {
try {
const body = await req.json();
const entitlement = body.entitlements?.premium_access;
const event = body.event;
const userId =
body.app_user_id ||
body.subscriber_attributes?.user_id?.value ||
body.customer ||
body.aliases?.[0];
if (!userId) {
console.error("user_id not found");
return new Response("user_id not found", { status: 400 });
}
// further logic...
} catch (e) {
console.error("Unexpected error", e);
return new Response("Server error", { status: 500 });
}
});