json response for downgrade user
This commit is contained in:
parent
6e8874e3b0
commit
c50b283b2d
|
@ -81,7 +81,6 @@ export async function upgradeUser(userId: T.UUID, subscription?: T.StripeSubscri
|
|||
|
||||
export async function downgradeUser(userId: T.UUID, subscriptionId?: string): Promise<T.DowngradeUserResponse> {
|
||||
await deleteCouchDbAuthUser(userId);
|
||||
console.log("in function downgrading user with subscriptionId", subscriptionId);
|
||||
if (subscriptionId) {
|
||||
stripe.subscriptions.del(subscriptionId);
|
||||
}
|
||||
|
|
|
@ -194,14 +194,16 @@ const authRouter = (passport: PassportStatic) => {
|
|||
router.post("/downgradeToBasic", async (req, res, next) => {
|
||||
try {
|
||||
if (!req.user) {
|
||||
return res.redirect("/");
|
||||
return res.send({ ok: false, error: "user not logged in" });
|
||||
}
|
||||
// @ts-ignore;
|
||||
console.log("will downgrade user with subscription id", req.user?.subscription?.id)
|
||||
await downgradeUser(req.user.userId, "subscription" in req.user
|
||||
? req.user.subscription?.id
|
||||
const subscription = "subscription" in req.user ? req.user.subscription : undefined;
|
||||
await downgradeUser(req.user.userId, subscription
|
||||
? subscription.id
|
||||
: undefined);
|
||||
res.redirect("/");
|
||||
res.send({
|
||||
ok: true,
|
||||
message: `account downgraded to basic${subscription ? " and subscription cancelled" : ""}`,
|
||||
});
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
|
|
|
@ -231,7 +231,11 @@
|
|||
const answer = confirm("Are you sure you want to downgrade your account? Your wordlist will be deleted forever. (Export it to CSV from the dictionary first if you want to keep it.)");
|
||||
if (answer) {
|
||||
fetch("/downgradeToBasic", { method: "POST" }).then((res) => res.json()).then((res) => {
|
||||
window.location = "/";
|
||||
if (res.ok) {
|
||||
window.location = "/";
|
||||
} else {
|
||||
alert("Error downgrading account");
|
||||
}
|
||||
}).catch((err) => {
|
||||
alert("Error downgrading account - check your connection");
|
||||
console.error(err);
|
||||
|
|
Loading…
Reference in New Issue