-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileForm.js
More file actions
56 lines (48 loc) · 1.42 KB
/
ProfileForm.js
File metadata and controls
56 lines (48 loc) · 1.42 KB
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
56
import { useRef, useContext } from "react";
import AuthContext from "../../store/auth-context";
import classes from "./ProfileForm.module.css";
import { useHistory } from "react-router-dom";
const ProfileForm = () => {
const newPasswordInputRef = useRef();
const authCtx = useContext(AuthContext);
const history = useHistory();
const submitHandler = (event) => {
event.preventDefault();
const enteredNewPassword = newPasswordInputRef.current.value;
// add validation
fetch(
"https://identitytoolkit.googleapis.com/v1/accounts:update?key=AIzaSyCVBuKSZk05KimdEmn1qpRiSCMAWp28kxM",
{
method: "POST",
body: JSON.stringify({
idToken: authCtx.token,
password: enteredNewPassword,
returnSecureToken: false,
}),
headers: {
"Content-Type": "application/json",
},
}
).then((res) => {
// assumption: Always succeeds!
history.replace("/");
});
};
return (
<form className={classes.form} onSubmit={submitHandler}>
<div className={classes.control}>
<label htmlFor="new-password">New Password</label>
<input
type="password"
id="new-password"
minLength="7"
ref={newPasswordInputRef}
/>
</div>
<div className={classes.action}>
<button>Change Password</button>
</div>
</form>
);
};
export default ProfileForm;