mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
refactor(experience): clear invalid totp code input (#4745)
This commit is contained in:
parent
c1d7df329a
commit
1c8ef14167
3 changed files with 16 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
import { useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
import VerificationCodeInput from '@/components/VerificationCode';
|
||||
import { type UserMfaFlow } from '@/types';
|
||||
|
@ -14,7 +14,11 @@ type Props = {
|
|||
|
||||
const TotpCodeVerification = ({ flow }: Props) => {
|
||||
const [code, setCode] = useState<string[]>([]);
|
||||
const { errorMessage, onSubmit } = useTotpCodeVerification(flow);
|
||||
const errorCallback = useCallback(() => {
|
||||
setCode([]);
|
||||
}, []);
|
||||
|
||||
const { errorMessage, onSubmit } = useTotpCodeVerification(flow, errorCallback);
|
||||
|
||||
return (
|
||||
<VerificationCodeInput
|
||||
|
|
|
@ -5,7 +5,7 @@ import { type ErrorHandlers } from '@/hooks/use-error-handler';
|
|||
import useSendMfaPayload from '@/hooks/use-send-mfa-payload';
|
||||
import { type UserMfaFlow } from '@/types';
|
||||
|
||||
const useTotpCodeVerification = (flow: UserMfaFlow) => {
|
||||
const useTotpCodeVerification = (flow: UserMfaFlow, errorCallback?: () => void) => {
|
||||
const [errorMessage, setErrorMessage] = useState<string>();
|
||||
const sendMfaPayload = useSendMfaPayload();
|
||||
|
||||
|
@ -22,10 +22,11 @@ const useTotpCodeVerification = (flow: UserMfaFlow) => {
|
|||
(code: string) => {
|
||||
void sendMfaPayload(
|
||||
{ flow, payload: { type: MfaFactor.TOTP, code } },
|
||||
invalidCodeErrorHandlers
|
||||
invalidCodeErrorHandlers,
|
||||
errorCallback
|
||||
);
|
||||
},
|
||||
[flow, invalidCodeErrorHandlers, sendMfaPayload]
|
||||
[errorCallback, flow, invalidCodeErrorHandlers, sendMfaPayload]
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
@ -31,7 +31,11 @@ const useSendMfaPayload = () => {
|
|||
const handleError = useErrorHandler();
|
||||
|
||||
return useCallback(
|
||||
async (apiOptions: SendMfaPayloadApiOptions, errorHandlers?: ErrorHandlers) => {
|
||||
async (
|
||||
apiOptions: SendMfaPayloadApiOptions,
|
||||
errorHandlers?: ErrorHandlers,
|
||||
errorCallback?: () => void
|
||||
) => {
|
||||
const [error, result] = await asyncSendMfaPayload(apiOptions);
|
||||
|
||||
if (error) {
|
||||
|
@ -39,6 +43,7 @@ const useSendMfaPayload = () => {
|
|||
...errorHandlers,
|
||||
...preSignInErrorHandler,
|
||||
});
|
||||
errorCallback?.();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue