Files
windmill/frontend/src/lib/loginError.ts
T
f52c117e76 feat: add native totp two-factor authentication for password login (#12620)
* feat: add native totp two-factor authentication for password login

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep login field spacing when the code field shows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep two-factor across a user overwrite and key the prompt to the submitted email

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: snapshot totp in the overwrite delete and audit wrong two-factor codes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: move two-factor to ee, add recovery codes, encrypt secrets, db-backed limit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: refuse a two-factor reset for an account without one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: serialize two-factor races with key rotation and ce enrollment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: argon2 recovery codes, otpauth link, totp field name, settings styling

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: serialize totp setup with admins key rotation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: two-factor setup wizard that asks for the password

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: ask for the two-factor code on its own login screen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: say two-factor is on with the recovery codes, red turn-off confirm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to 5456ade3c09011206acc20ab026dda49f15f9517

This commit updates the EE repository reference after PR #1005 was merged in windmill-ee-private.

Previous ee-repo-ref: 84c64720d625ed5a41b6ff0851f9d9b568b31c0b

New ee-repo-ref: 5456ade3c09011206acc20ab026dda49f15f9517

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-11-27 15:25:14 +01:00

37 lines
1.5 KiB
TypeScript

// Only messages the login endpoint is known to produce are shown. Anything else — a SQL error
// (which the API also returns as a 400, with the query and a source location), a proxy's HTML
// error page — would otherwise be printed verbatim to an unauthenticated visitor.
const KNOWN_LOGIN_ERRORS = ['Password login is disabled on this instance']
/** The password matched and the account asks for its authenticator code: a prompt, not a failure. */
export const TOTP_REQUIRED = 'Two-factor code required'
export const TOTP_INVALID_MESSAGE = 'Invalid authentication code.'
const GENERIC_LOGIN_ERROR = 'Could not sign you in. Please try again.'
// The API returns errors as plain text, prefixed by their class (e.g. "Bad request: Invalid
// login"); ApiError.message is only the HTTP status text.
export function loginErrorDetail(err: any): string {
const raw = typeof err?.body === 'string' ? err.body : err?.body?.error?.message
const body = typeof raw === 'string' ? raw : ''
return body.replace(/^(Bad request|Internal|Error): /, '').trim()
}
export function loginErrorMessage(err: any): string {
const detail = loginErrorDetail(err)
if (detail === 'Invalid login') {
return 'Invalid email or password.'
}
if (detail === 'Invalid two-factor code') {
return TOTP_INVALID_MESSAGE
}
if (err?.status === 429) {
return 'Too many login attempts. Please try again later.'
}
if (KNOWN_LOGIN_ERRORS.includes(detail)) {
return detail
}
return GENERIC_LOGIN_ERROR
}