-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForgotPassword.tsx
39 lines (32 loc) · 1.2 KB
/
ForgotPassword.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
import React, { useState } from "react";
import { auth } from "./Modules/firebase";
import GenericLoneDiv from "./GenericLoneDiv";
import InputElement from "./FormComponents/InputElement";
import { sendPasswordResetEmail } from "firebase/auth";
// Component for displaying the forgot password form
export default function ForgotPassword() {
const [email, setEmail] = useState("");
// Function for handling the form change
const handleEmailChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setEmail(event.target.value);
}
// Function for handling the form submit
const sendForgotPasswordLink = () => {
sendPasswordResetEmail(auth, email)
.then(() => {
// Password reset email sent!
// ..
})
.catch((error) => {
// ..
});
}
return (
<GenericLoneDiv heading={"Forgot Password"}>
<form onSubmit={sendForgotPasswordLink}>
<InputElement type={"email"} name={"email"} value={email} heading={"Email"} handleChange={handleEmailChange} required/>
<button>Send link</button>
</form>
</GenericLoneDiv>
)
}