mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-01-31 00:53:37 +00:00
36 lines
678 B
TypeScript
36 lines
678 B
TypeScript
|
import { auth } from "@clerk/nextjs";
|
||
|
|
||
|
import { db } from "@/lib/db";
|
||
|
|
||
|
const DAY_IN_MS = 86_400_000;
|
||
|
|
||
|
export const checkSubscription = async () => {
|
||
|
const { orgId } = auth();
|
||
|
|
||
|
if (!orgId) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
const orgSubscription = await db.orgSubscription.findUnique({
|
||
|
where: {
|
||
|
orgId,
|
||
|
},
|
||
|
select: {
|
||
|
stripeSubscriptionId: true,
|
||
|
stripeCurrentPeriodEnd: true,
|
||
|
stripeCustomerId: true,
|
||
|
stripePriceId: true,
|
||
|
},
|
||
|
});
|
||
|
|
||
|
if (!orgSubscription) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
const isValid =
|
||
|
orgSubscription.stripePriceId &&
|
||
|
orgSubscription.stripeCurrentPeriodEnd?.getTime()! + DAY_IN_MS > Date.now();
|
||
|
|
||
|
return !!isValid;
|
||
|
};
|