Skip to content

Commit 404e52f

Browse files
authored
fix: no input error on invalid passkey (#2141)
1 parent 31e85a5 commit 404e52f

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

backend/flow_api/flow/credential_usage/action_verify_passcode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func (a VerifyPasscode) Execute(c flowpilot.ExecutionContext) error {
6060
}
6161
}
6262

63-
return c.Error(shared.ErrorPasscodeInvalid)
63+
c.Input().SetError("code", shared.ErrorPasscodeInvalid)
64+
return c.Error(flowpilot.ErrorFormDataInvalid)
6465
}
6566

6667
if errors.Is(err, services.ErrorPasscodeMaxAttemptsReached) {

backend/flow_api/flow/mfa_creation/action_otp_code_verify.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func (a OTPCodeVerify) Execute(c flowpilot.ExecutionContext) error {
3939
secret := c.Stash().Get(shared.StashPathOTPSecret).String()
4040

4141
if !totp.Validate(code, secret) {
42-
return c.Error(shared.ErrorPasscodeInvalid)
42+
c.Input().SetError("otp_code", shared.ErrorPasscodeInvalid)
43+
return c.Error(flowpilot.ErrorFormDataInvalid)
4344
}
4445

4546
_ = c.Stash().Set(shared.StashPathUserHasOTPSecret, true)

backend/flow_api/flow/mfa_usage/action_otp_code_validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func (a OTPCodeValidate) Execute(c flowpilot.ExecutionContext) error {
6363
code := c.Input().Get("otp_code").String()
6464

6565
if !totp.Validate(code, userModel.OTPSecret.Secret) {
66-
return c.Error(shared.ErrorPasscodeInvalid)
66+
c.Input().SetError("otp_code", shared.ErrorPasscodeInvalid)
67+
return c.Error(flowpilot.ErrorFormDataInvalid)
6768
}
6869

6970
err = c.Stash().Set(shared.StashPathMFAUsageMethod, "totp")

backend/flow_api/flow/shared/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
var (
99
ErrorNotFound = flowpilot.NewFlowError("not_found", "The requested resource was not found.", http.StatusNotFound)
10-
ErrorPasscodeInvalid = flowpilot.NewFlowError("passcode_invalid", "The passcode is invalid.", http.StatusBadRequest)
1110
ErrorPasscodeMaxAttemptsReached = flowpilot.NewFlowError("passcode_max_attempts_reached", "The passcode was entered wrong too many times.", http.StatusUnauthorized)
1211
ErrorPasskeyInvalid = flowpilot.NewFlowError("passkey_invalid", "The passkey is invalid.", http.StatusUnauthorized)
1312
ErrorRateLimitExceeded = flowpilot.NewFlowError("rate_limit_exceeded", "The rate limit has been exceeded.", http.StatusTooManyRequests)
@@ -22,4 +21,5 @@ var (
2221
ErrorUnknownUsername = flowpilot.NewInputError("unknown_username_error", "The username is unknown.")
2322
ErrorUnknownEmail = flowpilot.NewInputError("unknown_email_error", "The email address is unknown.")
2423
ErrorInvalidUsername = flowpilot.NewInputError("invalid_username_error", "The username is invalid.")
24+
ErrorPasscodeInvalid = flowpilot.NewInputError("passcode_invalid", "The passcode is invalid.")
2525
)

frontend/elements/src/pages/LoginOTPPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const LoginOTPPAge = (props: Props) => {
4545
};
4646

4747
useEffect(() => {
48-
if (flowState.error?.code === "passcode_invalid") setPasscodeDigits([]);
48+
setPasscodeDigits([]);
4949
}, [flowState]);
5050

5151
return (

frontend/elements/src/pages/PasscodePage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ const PasscodePage = (props: Props) => {
6262
return submitPasscode(passcodeDigits.join(""));
6363
};
6464

65-
66-
6765
useEffect(() => {
6866
const timer = ttl > 0 && setInterval(() => setTtl(ttl - 1), 1000);
6967
return () => clearInterval(timer);
@@ -85,7 +83,7 @@ const PasscodePage = (props: Props) => {
8583
}, [resendAfter]);
8684

8785
useEffect(() => {
88-
if (flowState.error?.code === "passcode_invalid") setPasscodeDigits([]);
86+
setPasscodeDigits([]);
8987
if (flowState.payload.resend_after >= 0) {
9088
setResendAfter(flowState.payload.resend_after);
9189
}

0 commit comments

Comments
 (0)