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