From d6c6cc47d33341b17e430549d571a7ae12590e7d Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Thu, 24 Apr 2025 11:25:17 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Remove=20subscription=20rp?= =?UTF-8?q?c=20and=20enable=20pro=20features=20for=20self-hosted=20(#1687)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/src/data/get-user.ts | 3 ++- apps/web/src/trpc/routers/user.ts | 13 ------------- apps/web/src/utils/subscription.ts | 13 ++++--------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/apps/web/src/data/get-user.ts b/apps/web/src/data/get-user.ts index 489d4efb9..cf003f0bc 100644 --- a/apps/web/src/data/get-user.ts +++ b/apps/web/src/data/get-user.ts @@ -3,6 +3,7 @@ import { redirect } from "next/navigation"; import { cache } from "react"; import { requireUser } from "@/next-auth"; +import { isSelfHosted } from "@/utils/constants"; export const getUser = cache(async () => { const { userId } = await requireUser(); @@ -41,6 +42,6 @@ export const getUser = cache(async () => { timeZone: user.timeZone ?? undefined, timeFormat: user.timeFormat ?? undefined, weekStart: user.weekStart ?? undefined, - isPro: user.subscription?.active ?? false, + isPro: Boolean(isSelfHosted || user.subscription?.active), }; }); diff --git a/apps/web/src/trpc/routers/user.ts b/apps/web/src/trpc/routers/user.ts index acaff8774..1d3675c7d 100644 --- a/apps/web/src/trpc/routers/user.ts +++ b/apps/web/src/trpc/routers/user.ts @@ -9,7 +9,6 @@ import { z } from "zod"; import { env } from "@/env"; import { getS3Client } from "@/utils/s3"; import { createToken } from "@/utils/session"; -import { getSubscriptionStatus } from "@/utils/subscription"; import { createRateLimitMiddleware, @@ -52,18 +51,6 @@ export const user = router({ }, }); }), - subscription: publicProcedure.query( - async ({ ctx }): Promise<{ legacy?: boolean; active: boolean }> => { - if (!ctx.user || ctx.user.isGuest) { - // guest user can't have an active subscription - return { - active: false, - }; - } - - return await getSubscriptionStatus(ctx.user.id); - }, - ), changeName: privateProcedure .input( z.object({ diff --git a/apps/web/src/utils/subscription.ts b/apps/web/src/utils/subscription.ts index 344737672..d321c7040 100644 --- a/apps/web/src/utils/subscription.ts +++ b/apps/web/src/utils/subscription.ts @@ -1,5 +1,7 @@ import { prisma } from "@rallly/database"; +import { isSelfHosted } from "./constants"; + export const getSubscriptionStatus = async (userId: string) => { const user = await prisma.user.findUnique({ where: { @@ -9,19 +11,12 @@ export const getSubscriptionStatus = async (userId: string) => { subscription: { select: { active: true, - periodEnd: true, }, }, }, }); - if (user?.subscription?.active === true) { - return { - active: true, - } as const; - } - return { - active: false, - } as const; + active: user?.subscription?.active === true || isSelfHosted, + }; };