mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-05 21:26:05 +02:00
♻️ Remove subscription rpc and enable pro features for self-hosted (#1687)
This commit is contained in:
parent
90236e3424
commit
d6c6cc47d3
3 changed files with 6 additions and 23 deletions
|
@ -3,6 +3,7 @@ import { redirect } from "next/navigation";
|
||||||
import { cache } from "react";
|
import { cache } from "react";
|
||||||
|
|
||||||
import { requireUser } from "@/next-auth";
|
import { requireUser } from "@/next-auth";
|
||||||
|
import { isSelfHosted } from "@/utils/constants";
|
||||||
|
|
||||||
export const getUser = cache(async () => {
|
export const getUser = cache(async () => {
|
||||||
const { userId } = await requireUser();
|
const { userId } = await requireUser();
|
||||||
|
@ -41,6 +42,6 @@ export const getUser = cache(async () => {
|
||||||
timeZone: user.timeZone ?? undefined,
|
timeZone: user.timeZone ?? undefined,
|
||||||
timeFormat: user.timeFormat ?? undefined,
|
timeFormat: user.timeFormat ?? undefined,
|
||||||
weekStart: user.weekStart ?? undefined,
|
weekStart: user.weekStart ?? undefined,
|
||||||
isPro: user.subscription?.active ?? false,
|
isPro: Boolean(isSelfHosted || user.subscription?.active),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { z } from "zod";
|
||||||
import { env } from "@/env";
|
import { env } from "@/env";
|
||||||
import { getS3Client } from "@/utils/s3";
|
import { getS3Client } from "@/utils/s3";
|
||||||
import { createToken } from "@/utils/session";
|
import { createToken } from "@/utils/session";
|
||||||
import { getSubscriptionStatus } from "@/utils/subscription";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createRateLimitMiddleware,
|
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
|
changeName: privateProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { prisma } from "@rallly/database";
|
import { prisma } from "@rallly/database";
|
||||||
|
|
||||||
|
import { isSelfHosted } from "./constants";
|
||||||
|
|
||||||
export const getSubscriptionStatus = async (userId: string) => {
|
export const getSubscriptionStatus = async (userId: string) => {
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
@ -9,19 +11,12 @@ export const getSubscriptionStatus = async (userId: string) => {
|
||||||
subscription: {
|
subscription: {
|
||||||
select: {
|
select: {
|
||||||
active: true,
|
active: true,
|
||||||
periodEnd: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user?.subscription?.active === true) {
|
|
||||||
return {
|
return {
|
||||||
active: true,
|
active: user?.subscription?.active === true || isSelfHosted,
|
||||||
} as const;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
active: false,
|
|
||||||
} as const;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue