Skip to content

Commit 33e526a

Browse files
authored
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>
1 parent 6d502bb commit 33e526a

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/collections/AccountCollection.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DataCreateAccount, WebPushSubscription } from "stoat-api";
22

33
import type { Client } from "../Client.js";
4-
import { MFA } from "../classes/MFA.js";
4+
import { MFA, MFATicket } from "../classes/MFA.js";
55

66
/**
77
* Utility functions for working with accounts
@@ -111,12 +111,22 @@ export class AccountCollection {
111111
* Change account email
112112
* @param newEmail New email
113113
* @param currentPassword Current password
114+
* @param ticket MFA ticket, mandatory if account has MFA enabled
114115
*/
115-
changeEmail(newEmail: string, currentPassword: string): Promise<void> {
116-
return this.client.api.patch("/auth/account/change/email", {
117-
email: newEmail,
118-
current_password: currentPassword,
119-
});
116+
changeEmail(
117+
newEmail: string,
118+
currentPassword: string,
119+
ticket?: MFATicket,
120+
): Promise<void> {
121+
ticket?._consume();
122+
return this.client.api.patch(
123+
"/auth/account/change/email",
124+
{
125+
email: newEmail,
126+
current_password: currentPassword,
127+
},
128+
ticket ? { headers: { "X-MFA-Ticket": ticket.token } } : undefined
129+
);
120130
}
121131

122132
/**

0 commit comments

Comments
 (0)