-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathchallenge.tsx
55 lines (46 loc) · 1.7 KB
/
challenge.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Challenge component for verification code
const SignInChallenge = () => {
const [code, setCode] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const navigate = useNavigate();
const { submitCode, status, errorCode, errorMessage } = useCustomAuth();
const handleSubmit = async (e) => {
e.preventDefault();
setIsSubmitting(true);
try {
const result = await submitCode(code);
if (result === "SignIn.Completed") {
navigate("/success");
}
// If not successful, the form will show again with the error message
} catch (error) {
console.error("Code submission error:", error);
} finally {
setIsSubmitting(false);
}
};
return (
<div className="challenge-container">
<h2>Verification Required</h2>
<p>Please enter the verification code sent to your device.</p>
{errorMessage && (
<div className="error-message">{errorMessage}</div>
)}
<form onSubmit={handleSubmit}>
<div className="form-group">
<label htmlFor="code">Verification Code</label>
<input
type="text"
id="code"
value={code}
onChange={(e) => setCode(e.target.value)}
required
/>
</div>
<button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Verifying..." : "Submit Code"}
</button>
</form>
</div>
);
};