From 82c1626cdc997c0c02612023aeb4adf972904ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Guti=C3=A9rrez=20Fuentes?= Date: Sat, 1 Aug 2026 16:07:31 +0200 Subject: [PATCH 1/2] fix: allow passing MFA tickets when changing an account's email address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds an `MFATicket` parameter to the `AccountCollection.changeEmail`, which the backend mandates when the account has MFA enabled. The client still has to manually check whether passing a ticket is necessary by using `MFA.authenticatorEnabled`. Signed-off-by: Gabriel GutiƩrrez Fuentes --- src/collections/AccountCollection.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/collections/AccountCollection.ts b/src/collections/AccountCollection.ts index b695a355..dd93b0f6 100644 --- a/src/collections/AccountCollection.ts +++ b/src/collections/AccountCollection.ts @@ -1,7 +1,7 @@ import type { DataCreateAccount, WebPushSubscription } from "stoat-api"; import type { Client } from "../Client.js"; -import { MFA } from "../classes/MFA.js"; +import { MFA, MFATicket } from "../classes"; /** * Utility functions for working with accounts @@ -111,12 +111,24 @@ export class AccountCollection { * Change account email * @param newEmail New email * @param currentPassword Current password + * @param ticket MFA ticket, mandatory if account has MFA enabled */ - changeEmail(newEmail: string, currentPassword: string): Promise { - return this.client.api.patch("/auth/account/change/email", { - email: newEmail, - current_password: currentPassword, - }); + changeEmail( + newEmail: string, + currentPassword: string, + ticket?: MFATicket, + ): Promise { + ticket?._consume(); + return this.client.api.patch( + "/auth/account/change/email", + { + email: newEmail, + current_password: currentPassword, + }, + { + headers: ticket ? { "X-MFA-Ticket": ticket.token } : undefined, + }, + ); } /** From 14055bae0f47645f085dce774328fce9170e6068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Guti=C3=A9rrez=20Fuentes?= Date: Sat, 1 Aug 2026 18:15:03 +0200 Subject: [PATCH 2/2] style: fix formatting and linter issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel GutiƩrrez Fuentes --- src/collections/AccountCollection.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/collections/AccountCollection.ts b/src/collections/AccountCollection.ts index dd93b0f6..259d253e 100644 --- a/src/collections/AccountCollection.ts +++ b/src/collections/AccountCollection.ts @@ -1,7 +1,7 @@ import type { DataCreateAccount, WebPushSubscription } from "stoat-api"; import type { Client } from "../Client.js"; -import { MFA, MFATicket } from "../classes"; +import { MFA, MFATicket } from "../classes/MFA.js"; /** * Utility functions for working with accounts @@ -125,9 +125,7 @@ export class AccountCollection { email: newEmail, current_password: currentPassword, }, - { - headers: ticket ? { "X-MFA-Ticket": ticket.token } : undefined, - }, + ticket ? { headers: { "X-MFA-Ticket": ticket.token } } : undefined ); }