Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/dashboard/lib/trpc/routers/stripe/cancelSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { auth } from "@/lib/auth/server";
import { stripeEnv } from "@/lib/env";
import { TRPCError } from "@trpc/server";
import Stripe from "stripe";
Expand All @@ -11,6 +12,21 @@ export const cancelSubscription = t.procedure
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Stripe is not set up" });
}

const memberships = await auth.getOrganizationMemberList(ctx.workspace.orgId).catch((err) => {
console.error(err);
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Failed to fetch organization members",
});
});
if (memberships.data.length > 1) {
throw new TRPCError({
code: "PRECONDITION_FAILED",
message:
"Workspace has more than one member. You must remove all other members before downgrading to the free tier.",
});
}

const stripe = new Stripe(e.STRIPE_SECRET_KEY, {
apiVersion: "2023-10-16",
typescript: true,
Expand Down
Loading