Skip to content

Build your personal knowledge base with Trilium Notes

feat(login): distinguish recovery-code from TOTP errors

Elian Dorana3b5742cff42
diff --git a/apps/client/src/login_page.tsx b/apps/client/src/login_page.tsx
index 88c1a7c7cd..cd09eb3540 100644
--- a/apps/client/src/login_page.tsx
+++ b/apps/client/src/login_page.tsx
@@ -122,7 +122,16 @@ function PasswordLogin({ illustration, totpEnabled, error, errorId, onError }: {
}
const factor = resp.status === 401 ? (await resp.json().catch(() => ({}))).factor : undefined;
- onError(factor === "totp" ? t("login.incorrect-totp") : t("login.incorrect-password"));
+ if (factor === "totp") {
+ // This field accepts either a 6-digit TOTP or a recovery code (22 chars + "=="),
+ // so tailor the message to what was actually entered. This keys off the user's
+ // own input shape, never server state, so it can't reveal whether a given code
+ // was genuinely valid or already used.
+ const looksLikeRecoveryCode = /^.{22}==$/.test(totpRef.current?.value ?? "");
+ onError(t(looksLikeRecoveryCode ? "login.incorrect-recovery-code" : "login.incorrect-totp"));
+ } else {
+ onError(t("login.incorrect-password"));
+ }
} catch {
onError(t("login.incorrect-password"));
} finally {
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index de4ab2024f..78ca015ea0 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2857,6 +2857,7 @@
"remember-me": "Remember me",
"incorrect-password": "Password is incorrect. Please try again.",
"incorrect-totp": "One-time password is incorrect. Please try again.",
+ "incorrect-recovery-code": "Recovery code is incorrect, or has already been used.",
"too-many-attempts": "Too many login attempts. Please wait a few minutes and try again.",
"sign_in_with_sso": "Sign in with {{ssoIssuerName}}",
"sso-wrong-account": "That account isn't the one linked to this Trilium instance. Sign in with the linked account.",