Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: remap Invalid token error to Invalid code in changeEmail

Ammar Ahmedb8b7d37799b5
diff --git a/packages/core/src/api/user-manager.ts b/packages/core/src/api/user-manager.ts
index aa0970808..e97dead3f 100644
--- a/packages/core/src/api/user-manager.ts
+++ b/packages/core/src/api/user-manager.ts
@@ -548,18 +548,24 @@ class UserManager {
const email = newEmail.toLowerCase();
- await http.patch(
- `${constants.AUTH_HOST}${ENDPOINTS.patchUser}`,
- {
- type: "change_email",
- new_email: newEmail,
- password: await this.db.storage().hash(password, email, {
- usesFallback: await this.usesFallbackPWHash(password)
- }),
- verification_code: code
- },
- token
- );
+ try {
+ await http.patch(
+ `${constants.AUTH_HOST}${ENDPOINTS.patchUser}`,
+ {
+ type: "change_email",
+ new_email: newEmail,
+ password: await this.db.storage().hash(password, email, {
+ usesFallback: await this.usesFallbackPWHash(password)
+ }),
+ verification_code: code
+ },
+ token
+ );
+ } catch (e) {
+ const error = e as Error;
+ if (error.message === "Invalid token.") throw new Error("Invalid code.");
+ throw error;
+ }
}
recoverAccount(email: string) {