Initial Commit

This commit is contained in:
Ahmad 2024-02-14 21:30:10 -05:00
commit f3e2f01bd7
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
150 changed files with 13612 additions and 0 deletions

35
lib/subscription.ts Normal file
View file

@ -0,0 +1,35 @@
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;
};