fix: allow passing MFA tickets when changing an account's email address (#179)

* fix: allow passing MFA tickets when changing an account's email address

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 <me@gab.gf>

* style: fix formatting and linter issues

Signed-off-by: Gabriel Gutiérrez Fuentes <me@gab.gf>

---------

Signed-off-by: Gabriel Gutiérrez Fuentes <me@gab.gf>
This commit is contained in:
Gabriel Gutiérrez Fuentes
2026-08-03 18:17:02 +02:00
committed by GitHub
parent 6d502bb194
commit 33e526aa10
+16 -6
View File
@@ -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/MFA.js";
/**
* Utility functions for working with accounts
@@ -111,12 +111,22 @@ 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<void> {
return this.client.api.patch("/auth/account/change/email", {
email: newEmail,
current_password: currentPassword,
});
changeEmail(
newEmail: string,
currentPassword: string,
ticket?: MFATicket,
): Promise<void> {
ticket?._consume();
return this.client.api.patch(
"/auth/account/change/email",
{
email: newEmail,
current_password: currentPassword,
},
ticket ? { headers: { "X-MFA-Ticket": ticket.token } } : undefined
);
}
/**