From d5ed73ae57bf14929c084e4d7faa64ff6845c30f Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 22 Oct 2024 11:46:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20confirm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/app/models/user.ts | 3 --- apps/api/app/routes/account/index.ts | 7 +++++++ apps/web/src/routes/confirm.svelte | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/api/app/models/user.ts b/apps/api/app/models/user.ts index 9b5af0b9..a0fe8e6d 100644 --- a/apps/api/app/models/user.ts +++ b/apps/api/app/models/user.ts @@ -247,9 +247,6 @@ schema.method("confirmKey", function (this: UserDocument) { }); schema.method("confirm", function (this: UserDocument, key: string) { - if (this.security.confirmed) { - return; - } assert(key && this.confirmKey() === key, `Wrong confirm link.`); this.security.confirmed = true; this.security.confirmKey = null; diff --git a/apps/api/app/routes/account/index.ts b/apps/api/app/routes/account/index.ts index 5f9b8815..817e2ca2 100644 --- a/apps/api/app/routes/account/index.ts +++ b/apps/api/app/routes/account/index.ts @@ -259,8 +259,15 @@ router.post("/confirm", async (ctx: Context) => { throw createError(404, "Can't find user: " + ctx.request.body.email); } + if (user.security.confirmed) { + ctx.redirect("/login"); + return; + } + await user.confirm(ctx.request.body.key); + ctx.state.user = user; + await sendAuthInfo(ctx); }); diff --git a/apps/web/src/routes/confirm.svelte b/apps/web/src/routes/confirm.svelte index 56edbc88..87a6cd6f 100644 --- a/apps/web/src/routes/confirm.svelte +++ b/apps/web/src/routes/confirm.svelte @@ -6,6 +6,13 @@ import type { LoadInput } from "@sveltejs/kit"; export async function load(input: LoadInput) { + if (typeof window === "undefined") { + // Bug in node 20+, handle client-side + return { + status: 200, + body: {}, + }; + } const { post, setAuthData } = useLoad(input, useAccount, useRest); await post("/account/confirm", { key: input.url.searchParams.get("key"),