From a8af106606763447b43423300774ec07d90bed33 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 11 Jun 2024 14:18:20 -0700 Subject: [PATCH] Connected set new password to backend --- Client/src/Pages/ForgotPassword/index.jsx | 27 +++++---- Client/src/Pages/SetNewPassword/index.jsx | 71 +++++++++++++++++++++-- Client/src/Validation/validation.js | 19 +++++- Server/controllers/authController.js | 2 +- Server/db/MongoDB.js | 5 +- 5 files changed, 105 insertions(+), 19 deletions(-) diff --git a/Client/src/Pages/ForgotPassword/index.jsx b/Client/src/Pages/ForgotPassword/index.jsx index d5ec84088..b77865ebb 100644 --- a/Client/src/Pages/ForgotPassword/index.jsx +++ b/Client/src/Pages/ForgotPassword/index.jsx @@ -12,6 +12,7 @@ import axios from "axios"; const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL; const ForgotPassword = () => { + const [isLoading, setIsLoading] = useState(false); // Used to disable the button while loading so user doesn't submit multiple times const [errors, setErrors] = useState({}); const [form, setForm] = useState({ email: "", @@ -39,16 +40,21 @@ const ForgotPassword = () => { }; const handleSubmit = async () => { - const { error } = recoveryValidation.validate(form); - if (error === undefined) { - try { - const res = await axios.post(`${BASE_URL}/auth/recovery/request`, form); - console.log(res); - } catch (error) { - console.log(error); + //TODO show loading spinner + setIsLoading(true); + try { + const { error } = recoveryValidation.validate(form); + if (error !== undefined) { + throw error; } - } else { + const res = await axios.post(`${BASE_URL}/auth/recovery/request`, form); + // TODO properly display success + alert(JSON.stringify(res.data)); + } catch (error) { + //TODO display error (Toast?) alert(error); + } finally { + setIsLoading(false); } }; return ( @@ -72,13 +78,14 @@ const ForgotPassword = () => {