I am using NextJs to create a stripe customer subscription and I have set up a webhook to interract with my stripe account, but I am not seeing the users data in my supabase table.
First here is the code:
import getRawBody from "raw-body";
import { stripe } from "src/pricing/utils/stripe";
import { supabase } from "supabase";
export const config = {
api: {
bodyParser: false,
},
};
export default async function handler(req, res) {
const signature = req.headers["stripe-signature"];
const signingSecret = process.env.STRIPE_SIGNING_SECRET;
let event;
try {
const rawBody = await getRawBody(req, { limit: "2mb" });
event = stripe.webhooks.constructEvent(rawBody, signature, signingSecret);
} catch (error) {
console.log("Webhook signature verification failed");
return res.status(400).end();
}
try {
switch (event.type) {
case "customer.subscription.updated":
await updateSubscription(event);
break;
case "customer.subscription.deleted":
await deleteSubsctiption(event);
break;
}
res.send({ success: true });
console.log(event);
return;
} catch (error) {
console.log(error.message);
res.send({ status: false });
return;
}
}
async function updateSubscription(event) {
const subscription = event.data.object;
const stripe_customer_id = subscription.customer;
const subscription_status = subscription.status;
const price = subscription.items.data[0].price.id;
const { data: profile } = await supabase
.from("profile")
.select("*")
.eq("stripe_customer_id", stripe_customer_id)
.single();
if (profile) {
const updatedSubscription = {
subscription_status,
price,
};
await supabase
.from("profile")
.update(updatedSubscription)
.eq("stripe_customer_id", stripe_customer_id);
} else {
const customer = await stripe.customers.retrieve(stripe_customer_id);
const name = customer.name;
const email = customer.email;
const newProfile = {
name,
email,
stripe_customer_id,
subscription_status,
price,
};
await supabase.auth.admin.createUser({
email,
email_confirm: true,
user_metadata: newProfile,
});
}
return;
}
Before seting up my function this is displaying on my supabase authentication tab. Before setting Up Supabase Function
But after setting up a function I cant see anything, please help me out on how i can set up my supabase function so that the info can be displayed on my supabase table
I made a query to my databasedatabase query
And I could find the data in the Supabase Database.
But, I can't use the data, or move it to a table