diff --git a/account/src/lib/user-utils.ts b/account/src/lib/user-utils.ts index e7e5386..b43f723 100644 --- a/account/src/lib/user-utils.ts +++ b/account/src/lib/user-utils.ts @@ -81,6 +81,7 @@ export async function upgradeUser(userId: T.UUID, subscription?: T.StripeSubscri export async function downgradeUser(userId: T.UUID, subscriptionId?: string): Promise { await deleteCouchDbAuthUser(userId); + console.log("in function downgrading user with subscriptionId", subscriptionId); if (subscriptionId) { stripe.subscriptions.del(subscriptionId); } diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index 8b581eb..15e5edb 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -196,6 +196,8 @@ const authRouter = (passport: PassportStatic) => { if (!req.user) { return res.redirect("/"); } + // @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 : undefined); diff --git a/account/views/user.ejs b/account/views/user.ejs index 1485ce7..e2412c1 100644 --- a/account/views/user.ejs +++ b/account/views/user.ejs @@ -76,7 +76,7 @@ <% } %> <% if (user.tester && user.level === "student" && user.subscription) { %>

Current subscription: <% if (user.subscription.metadata.cycle === "monthly") { %>$1/month<% } else { %>$10/year<% } %>

-

Downgrade your account to cancel your subscription

+

Downgrade to cancel your subscription

<% } %> <% if (user.email) { %>

Password

@@ -228,12 +228,10 @@ } } function handleDowngrade() { - 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 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) { fetch("/downgradeToBasic", { method: "POST" }).then((res) => res.json()).then((res) => { - if (res.ok) { - window.location = "/"; - } + window.location = "/"; }).catch((err) => { alert("Error downgrading account - check your connection"); console.error(err);