Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: webhooks-based approach #16

Merged
merged 12 commits into from
Mar 31, 2023
Prev Previous commit
Next Next commit
fix
  • Loading branch information
iuioiua committed Mar 27, 2023
commit 73518fc626d9898b73bca2b1653321af24e22f5a
2 changes: 1 addition & 1 deletion routes/api/customer.ts
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ export const handler: Handlers = {
});

await supabaseAdminClient
.from("users_subscriptions")
.from("subscriptions")
.update({ stripe_customer_id: customer.id })
.eq("user_id", user_id)
.throwOnError();
4 changes: 2 additions & 2 deletions routes/api/subscription.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ export const handler: Handlers = {
switch (event.type) {
case "customer.subscription.created": {
await supabaseAdminClient
.from("users_subscriptions")
.from("subscriptions")
.update({ is_subscribed: true })
// @ts-ignore: Property 'customer' actually does exist on type 'Object'
.eq("stripe_customer_id", event.data.object.customer)
@@ -38,7 +38,7 @@ export const handler: Handlers = {
}
case "customer.subscription.deleted": {
await supabaseAdminClient
.from("users_subscriptions")
.from("subscriptions")
.update({ is_subscribed: false })
// @ts-ignore: Property 'customer' actually does exist on type 'Object'
.eq("stripe_customer_id", event.data.object.customer)
2 changes: 1 addition & 1 deletion routes/dashboard/_middleware.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ export async function handler(
ctx.state.session = session;

const { data } = await supabaseClient
.from("users_subscriptions")
.from("subscriptions")
.select("stripe_customer_id, is_subscribed")
.single()
.throwOnError();