diff --git a/src/components/Forgot.jsx b/src/components/Forgot.jsx index b7802a86..56e12e80 100644 --- a/src/components/Forgot.jsx +++ b/src/components/Forgot.jsx @@ -42,23 +42,22 @@ const ForgotPage = (props) => { const [done, setDone] = useState(false); const [errors, setErrors] = useState(""); - const onSubmit = (e) => { + const onSubmit = async (e) => { e.preventDefault(); if (!loading) { setLoading(true); setErrors(""); let email = document.getElementById("email").value; - props.profile.Forgot(email) - .then((msg) => { - if (msg.error) { - setLoading(false); - setErrors(msg.error); - } else { - setLoading(false); - setDone(true); - setErrors(""); - } - }); + let msg = await props.profile.Forgot(email) + if (msg.error) { + setLoading(false); + setErrors(msg.error); + } else { + setLoading(false); + setDone(true); + setErrors(""); + } + } }; diff --git a/src/components/Profile.js b/src/components/Profile.js index 04f2d8a2..a8361e03 100644 --- a/src/components/Profile.js +++ b/src/components/Profile.js @@ -1,3 +1,4 @@ +import { ControlCameraSharp } from "@material-ui/icons"; import { defaults } from "../Defaults"; import PropTypes from "prop-types"; @@ -486,24 +487,23 @@ class Profile { } else { await fetch(ENDPOINTS.forgot, { method: "POST", - body: { + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ email: email, forgot: true, - }, - json: true, + }), }) - .then((res) => { - if (res.statusCode === 200) { + .then(async (res) => { + let resJSON = await res.json(); + if (resJSON.statusCode === 200) { return resp; } else { - if (res.errorMessage) { - console.error(res.errorMessage); - } - if (res.body) { - return res.body; + if (resJSON.body) { + resp.error = resJSON.body; } else { resp.error = "Unexpected Error"; - return resp; } } }) @@ -511,9 +511,9 @@ class Profile { resp.error = error + "An error occured when attempting to general url"; - return resp; }); } + return resp; } } async Reset(email, password, conpassword, magic) {