MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / ForgotPassword

Function ForgotPassword

client/src/component/ForgotPassword.jsx:9–130  ·  view source on GitHub ↗
({ showAlert, mode })

Source from the content-addressed store, hash-verified

7const VITE_SERVER_PORT = import.meta.env.VITE_SERVER_PORT || 'https://bitbox-uxbo.onrender.com';
8
9const ForgotPassword = ({ showAlert, mode }) => {
10 const [forgotEmail, setForgotEmail] = useState("");
11 const [loading, setLoading] = useState(false);
12 const navigate = useNavigate();
13 const handleForgotPassword = async () => {
14 setLoading(true);
15 try {
16 const response = await fetch(`${VITE_SERVER_PORT}/api/auth/ResetByEmail`, {
17 method: "POST",
18 headers: {
19 "Content-Type": "application/json",
20 },
21 body: JSON.stringify({ email: forgotEmail }),
22 });
23
24 const data = await response.json();
25
26 if (response.ok) {
27 toast.success(data.message || "Reset email sent successfully!");
28 setForgotEmail("");
29 navigate("/login");
30 } else {
31 showAlert(data.error || "Failed to send reset email", "danger");
32 }
33 } catch (error) {
34 console.error("Error during password reset:", error);
35 showAlert("An error occurred. Please try again later.", "danger");
36 } finally {
37 setLoading(false);
38 }
39 };
40
41
42 return (
43 <div className="flex justify-center h-[85vh] items-center mt-[7rem]">
44 <div
45 className='wrapper'
46 style={{
47 backgroundColor: mode === "dark" ? "black" : "white",
48 color: mode === "dark" ? "white" : "black",
49 }}
50 >
51 <div className='form'>
52 <h1 className='title'>Reset Password</h1>
53 <span className='title-line'></span>
54 <div className='inp'>
55 <Input
56 type='email'
57 placeholder='Enter your email'
58 value={forgotEmail}
59 onChange={(e) => setForgotEmail(e.target.value)}
60 required
61 style={{
62 backgroundColor: mode === "dark" ? "black" : "white",
63 color: mode === "dark" ? "white" : "black",
64 }}
65 autoComplete="on"
66 />

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected