mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-04 04:33:10 +00:00
Initial Commit
This commit is contained in:
commit
f3e2f01bd7
150 changed files with 13612 additions and 0 deletions
35
lib/subscription.ts
Normal file
35
lib/subscription.ts
Normal 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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue