From 584c35e6b88eba699b276ca0337bba567f4f7761 Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Tue, 31 Jan 2023 15:10:08 +0000 Subject: [PATCH] Added reset password functionality - Display reset password option on log in modal only - Display `resetPassword` modal only when state is not login or signup - Use Firebase hook to send email with reset instructions --- src/components/Modal/Auth/AuthModal.tsx | 16 ++- src/components/Modal/Auth/Login.tsx | 28 ++++- src/components/Modal/Auth/ResetPassword.tsx | 107 ++++++++++++++++++++ 3 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 src/components/Modal/Auth/ResetPassword.tsx diff --git a/src/components/Modal/Auth/AuthModal.tsx b/src/components/Modal/Auth/AuthModal.tsx index 41f07be..e9e5b46 100644 --- a/src/components/Modal/Auth/AuthModal.tsx +++ b/src/components/Modal/Auth/AuthModal.tsx @@ -16,6 +16,7 @@ import { useAuthState } from "react-firebase-hooks/auth"; import { useRecoilState } from "recoil"; import AuthInputs from "./AuthInputs"; import OAuthButtons from "./OAuthButtons"; +import ResetPassword from "./ResetPassword"; const AuthModal: React.FC = () => { const [modalState, setModalState] = useRecoilState(authModalState); @@ -57,11 +58,16 @@ const AuthModal: React.FC = () => { justify="center" width="70%" > - - {/* OR */} - - - {/* */} + {modalState.view === "login" || modalState.view === "signup" ? ( + <> + + {/* OR */} + + + + ) : ( + + )} diff --git a/src/components/Modal/Auth/Login.tsx b/src/components/Modal/Auth/Login.tsx index c6d253d..df97ba9 100644 --- a/src/components/Modal/Auth/Login.tsx +++ b/src/components/Modal/Auth/Login.tsx @@ -95,12 +95,38 @@ const Login: React.FC = () => { {FIREBASE_ERRORS[error?.message as keyof typeof FIREBASE_ERRORS]} - + + + Forgot your password? + + + setAuthModalState((prev) => ({ + ...prev, + view: "resetPassword", + })) + } + > + Reset Password + + + Want to join the circus? { + const setAuthModalState = useSetRecoilState(authModalState); + const [email, setEmail] = useState(""); + const [success, setSuccess] = useState(false); + const [sendPasswordResetEmail, sending, error] = + useSendPasswordResetEmail(auth); + + const onSubmit = async (event: React.FormEvent) => { + event.preventDefault(); + + await sendPasswordResetEmail(email); + setSuccess(true); + }; + return ( + + Website logo + + Reset your password + + {success ? ( + Check your email + ) : ( + <> + + Enter the email associated with your account and we will send you a + reset link + +
+ setEmail(event.target.value)} + fontSize="10pt" + _placeholder={{ color: "gray.500" }} + _hover={{ + bg: "white", + border: "1px solid", + borderColor: "blue.500", + }} + _focus={{ + outline: "none", + bg: "white", + border: "1px solid", + borderColor: "blue.500", + }} + bg="gray.50" + /> + + {error?.message} + + +
+ + )} + + + setAuthModalState((prev) => ({ + ...prev, + view: "login", + })) + } + > + LOGIN + + + + setAuthModalState((prev) => ({ + ...prev, + view: "signup", + })) + } + > + SIGN UP + + +
+ ); +}; +export default ResetPassword;