commit
a3d3b353a1
|
@ -32,11 +32,12 @@ export default async function checkSubscriptionByEmail(email: string) {
|
|||
customer.subscriptions?.data.some((subscription) => {
|
||||
subscription.current_period_end;
|
||||
|
||||
active = subscription.items.data.some(
|
||||
(e) =>
|
||||
(e.price.id === MONTHLY_PRICE_ID && e.price.active === true) ||
|
||||
(e.price.id === YEARLY_PRICE_ID && e.price.active === true)
|
||||
);
|
||||
active =
|
||||
subscription.items.data.some(
|
||||
(e) =>
|
||||
(e.price.id === MONTHLY_PRICE_ID && e.price.active === true) ||
|
||||
(e.price.id === YEARLY_PRICE_ID && e.price.active === true)
|
||||
) || false;
|
||||
stripeSubscriptionId = subscription.id;
|
||||
currentPeriodStart = subscription.current_period_start * 1000;
|
||||
currentPeriodEnd = subscription.current_period_end * 1000;
|
||||
|
@ -44,7 +45,7 @@ export default async function checkSubscriptionByEmail(email: string) {
|
|||
});
|
||||
|
||||
return {
|
||||
active,
|
||||
active: active || false,
|
||||
stripeSubscriptionId,
|
||||
currentPeriodStart,
|
||||
currentPeriodEnd,
|
||||
|
|
|
@ -48,6 +48,7 @@ export default async function postLink(
|
|||
return { response: "Collection is not accessible.", status: 401 };
|
||||
|
||||
link.collection.id = findCollection.id;
|
||||
link.collection.ownerId = findCollection.ownerId;
|
||||
} else {
|
||||
const collection = await prisma.collection.create({
|
||||
data: {
|
||||
|
|
|
@ -17,15 +17,7 @@ export default async function verifySubscription(
|
|||
|
||||
const currentDate = new Date();
|
||||
|
||||
if (
|
||||
subscription &&
|
||||
currentDate > subscription.currentPeriodEnd &&
|
||||
!subscription.active
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!subscription || currentDate > subscription.currentPeriodEnd) {
|
||||
if (!subscription?.active || currentDate > subscription.currentPeriodEnd) {
|
||||
const {
|
||||
active,
|
||||
stripeSubscriptionId,
|
||||
|
@ -59,15 +51,21 @@ export default async function verifySubscription(
|
|||
},
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
} else if (!active) {
|
||||
const subscription = await prisma.subscription.findFirst({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!active) {
|
||||
if (user.username)
|
||||
// await prisma.user.update({
|
||||
// where: { id: user.id },
|
||||
// data: { username: null },
|
||||
// });
|
||||
return null;
|
||||
if (subscription)
|
||||
await prisma.subscription.delete({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ export default async function verifyUser({
|
|||
}
|
||||
|
||||
if (STRIPE_SECRET_KEY) {
|
||||
const subscribedUser = verifySubscription(user);
|
||||
const subscribedUser = await verifySubscription(user);
|
||||
|
||||
if (!subscribedUser) {
|
||||
res.status(401).json({
|
||||
|
|
Ŝarĝante…
Reference in New Issue