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> {
|
export async function downgradeUser(userId: T.UUID, subscriptionId?: string): Promise<T.DowngradeUserResponse> {
|
||||||
await deleteCouchDbAuthUser(userId);
|
await deleteCouchDbAuthUser(userId);
|
||||||
console.log("in function downgrading user with subscriptionId", subscriptionId);
|
|
||||||
if (subscriptionId) {
|
if (subscriptionId) {
|
||||||
stripe.subscriptions.del(subscriptionId);
|
stripe.subscriptions.del(subscriptionId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,14 +194,16 @@ const authRouter = (passport: PassportStatic) => {
|
||||||
router.post("/downgradeToBasic", async (req, res, next) => {
|
router.post("/downgradeToBasic", async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
return res.redirect("/");
|
return res.send({ ok: false, error: "user not logged in" });
|
||||||
}
|
}
|
||||||
// @ts-ignore;
|
const subscription = "subscription" in req.user ? req.user.subscription : undefined;
|
||||||
console.log("will downgrade user with subscription id", req.user?.subscription?.id)
|
await downgradeUser(req.user.userId, subscription
|
||||||
await downgradeUser(req.user.userId, "subscription" in req.user
|
? subscription.id
|
||||||
? req.user.subscription?.id
|
|
||||||
: undefined);
|
: undefined);
|
||||||
res.redirect("/");
|
res.send({
|
||||||
|
ok: true,
|
||||||
|
message: `account downgraded to basic${subscription ? " and subscription cancelled" : ""}`,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
next(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.)");
|
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) {
|
if (answer) {
|
||||||
fetch("/downgradeToBasic", { method: "POST" }).then((res) => res.json()).then((res) => {
|
fetch("/downgradeToBasic", { method: "POST" }).then((res) => res.json()).then((res) => {
|
||||||
window.location = "/";
|
if (res.ok) {
|
||||||
|
window.location = "/";
|
||||||
|
} else {
|
||||||
|
alert("Error downgrading account");
|
||||||
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
alert("Error downgrading account - check your connection");
|
alert("Error downgrading account - check your connection");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
Loading…
Reference in New Issue