Skip to content

Commit

Permalink
🐛 Fix confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
coyotte508 committed Oct 22, 2024
1 parent 62294ab commit d5ed73a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 0 additions & 3 deletions apps/api/app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions apps/api/app/routes/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/routes/confirm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthData>("/account/confirm", {
key: input.url.searchParams.get("key"),
Expand Down

0 comments on commit d5ed73a

Please sign in to comment.