diff --git a/packages/auth/src/auth.ts b/packages/auth/src/auth.ts index 9822f271..a4bc0ea4 100644 --- a/packages/auth/src/auth.ts +++ b/packages/auth/src/auth.ts @@ -10,6 +10,7 @@ import { env } from "next-runtime-env"; import type { dbClient } from "@kan/db/client"; import * as memberRepo from "@kan/db/repository/member.repo"; +import * as subscriptionRepo from "@kan/db/repository/subscription.repo"; import * as userRepo from "@kan/db/repository/user.repo"; import * as workspaceRepo from "@kan/db/repository/workspace.repo"; import * as schema from "@kan/db/schema"; @@ -203,6 +204,24 @@ export const initAuth = (db: dbClient) => { }, }; }, + onSubscriptionComplete: async ({ + subscription, + stripeSubscription, + }) => { + // Set unlimited seats to true for pro plans + if (subscription.plan === "pro") { + await subscriptionRepo.updateByStripeSubscriptionId( + db, + stripeSubscription.id, + { + unlimitedSeats: true, + }, + ); + console.log( + `Pro subscription ${stripeSubscription.id} activated with unlimited seats`, + ); + } + }, }, }), ] diff --git a/packages/db/src/repository/workspace.repo.ts b/packages/db/src/repository/workspace.repo.ts index 09dd19bb..3ef933d5 100644 --- a/packages/db/src/repository/workspace.repo.ts +++ b/packages/db/src/repository/workspace.repo.ts @@ -127,6 +127,7 @@ export const getByPublicIdWithMembers = ( plan: true, status: true, seats: true, + unlimitedSeats: true, periodStart: true, periodEnd: true, },