From 795516b3ee8640cf67b01b776b304837a6dc02b6 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Wed, 3 Sep 2025 00:25:25 -0700 Subject: [PATCH] fix(demo): put get plans inside a sync function (#4372) --- demo/nextjs/lib/auth.ts | 60 ++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/demo/nextjs/lib/auth.ts b/demo/nextjs/lib/auth.ts index f740894b..08114bdc 100644 --- a/demo/nextjs/lib/auth.ts +++ b/demo/nextjs/lib/auth.ts @@ -41,15 +41,6 @@ if (!dialect) { throw new Error("No dialect found"); } -const PRO_PRICE_ID = { - default: "price_1RoxnRHmTADgihIt4y8c0lVE", - annual: "price_1RoxnoHmTADgihItzFvVP8KT", -}; -const PLUS_PRICE_ID = { - default: "price_1RoxnJHmTADgihIthZTLmrPn", - annual: "price_1Roxo5HmTADgihItEbJu5llL", -}; - const baseURL: string | undefined = process.env.VERCEL === "1" ? process.env.VERCEL_ENV === "production" @@ -200,24 +191,43 @@ export const auth = betterAuth({ subscription: { enabled: true, allowReTrialsForDifferentPlans: true, - plans: [ - { - name: "Plus", - priceId: PLUS_PRICE_ID.default, - annualDiscountPriceId: PLUS_PRICE_ID.annual, - freeTrial: { - days: 7, + plans: () => { + const PRO_PRICE_ID = { + default: + process.env.STRIPE_PRO_PRICE_ID ?? + "price_1RoxnRHmTADgihIt4y8c0lVE", + annual: + process.env.STRIPE_PRO_ANNUAL_PRICE_ID ?? + "price_1RoxnoHmTADgihItzFvVP8KT", + }; + const PLUS_PRICE_ID = { + default: + process.env.STRIPE_PLUS_PRICE_ID ?? + "price_1RoxnJHmTADgihIthZTLmrPn", + annual: + process.env.STRIPE_PLUS_ANNUAL_PRICE_ID ?? + "price_1Roxo5HmTADgihItEbJu5llL", + }; + + return [ + { + name: "Plus", + priceId: PLUS_PRICE_ID.default, + annualDiscountPriceId: PLUS_PRICE_ID.annual, + freeTrial: { + days: 7, + }, }, - }, - { - name: "Pro", - priceId: PRO_PRICE_ID.default, - annualDiscountPriceId: PRO_PRICE_ID.annual, - freeTrial: { - days: 7, + { + name: "Pro", + priceId: PRO_PRICE_ID.default, + annualDiscountPriceId: PRO_PRICE_ID.annual, + freeTrial: { + days: 7, + }, }, - }, - ], + ]; + }, }, }), deviceAuthorization({