MCPcopy
hub / github.com/shadcn-ui/taxonomy / getUserSubscriptionPlan

Function getUserSubscriptionPlan

lib/subscription.ts:7–39  ·  view source on GitHub ↗
(
  userId: string
)

Source from the content-addressed store, hash-verified

5import { db } from "@/lib/db"
6
7export async function getUserSubscriptionPlan(
8 userId: string
9): Promise<UserSubscriptionPlan> {
10 const user = await db.user.findFirst({
11 where: {
12 id: userId,
13 },
14 select: {
15 stripeSubscriptionId: true,
16 stripeCurrentPeriodEnd: true,
17 stripeCustomerId: true,
18 stripePriceId: true,
19 },
20 })
21
22 if (!user) {
23 throw new Error("User not found")
24 }
25
26 // Check if user is on a pro plan.
27 const isPro =
28 user.stripePriceId &&
29 user.stripeCurrentPeriodEnd?.getTime() + 86_400_000 > Date.now()
30
31 const plan = isPro ? proPlan : freePlan
32
33 return {
34 ...plan,
35 ...user,
36 stripeCurrentPeriodEnd: user.stripeCurrentPeriodEnd?.getTime(),
37 isPro,
38 }
39}

Callers 3

BillingPageFunction · 0.90
GETFunction · 0.90
POSTFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected