fix(2fa): show correct error for invalid TOTP code

The verify-totp handler checked for the error code
INVALID_TWO_FACTOR_AUTHENTICATION, which no longer exists in
better-auth 1.6.23 (the two-factor plugin now returns INVALID_CODE).
As a result, entering a wrong TOTP code fell through to the generic
catch and showed "Error verifying 2FA code / Unknown error" instead of
a clear "Invalid verification code" message.

Match the current better-auth error code so the specific, actionable
message is shown.
This commit is contained in:
Mauricio Siu
2026-07-20 18:20:56 -06:00
parent cbec72ed80
commit 6d65a36aac

View File

@@ -100,7 +100,7 @@ export const Enable2FA = () => {
});
if (result.error) {
if (result.error.code === "INVALID_TWO_FACTOR_AUTHENTICATION") {
if (result.error.code === "INVALID_CODE") {
toast.error("Invalid verification code");
return;
}