From c7fa16296f989489ea8de19377353621313a7931 Mon Sep 17 00:00:00 2001 From: Mohamed Hadri Date: Wed, 31 Aug 2022 02:53:15 +0300 Subject: [PATCH 1/3] added reset password func --- context/AuthContext.js | 9 ++++-- data/products.json | 2 +- src/components/EditProfile/EditProfile.jsx | 31 ++++++++++++++++++- .../__snapshots__/EditProfile.test.jsx.snap | 13 ++++++-- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/context/AuthContext.js b/context/AuthContext.js index 0808f9e..d7e5c72 100644 --- a/context/AuthContext.js +++ b/context/AuthContext.js @@ -2,6 +2,7 @@ import { auth } from "firebase.config"; import { createUserWithEmailAndPassword, onAuthStateChanged, + sendPasswordResetEmail, signInWithEmailAndPassword, signOut, } from "firebase/auth"; @@ -46,9 +47,13 @@ export const AuthContextProvider = ({ children }) => { setUser(null); await signOut(auth); }; - + const resetPassword = (email) => { + return sendPasswordResetEmail(auth, email); + }; return ( - + {loading ? null : children} ); diff --git a/data/products.json b/data/products.json index de1eb84..529a283 100644 --- a/data/products.json +++ b/data/products.json @@ -595,7 +595,7 @@ "condition": "New", "seller": { "id": 88888888, - "displayName": "Umut Polat", + "displayName": "Nouh Rastanawi", "email": "studentstoretemp@gmail.com", "image": "https://www.random-name-generator.com/images/faces/male-white/37.jpg?ezimgfmt=rs:148x143/rscb1/ng:webp/ngcb1" }, diff --git a/src/components/EditProfile/EditProfile.jsx b/src/components/EditProfile/EditProfile.jsx index 3203c0b..b653131 100644 --- a/src/components/EditProfile/EditProfile.jsx +++ b/src/components/EditProfile/EditProfile.jsx @@ -5,16 +5,20 @@ import { updateProfile } from "firebase/auth"; import { useRouter } from "next/router"; import { useTranslation } from "next-i18next"; import * as React from "react"; +import { useRef } from "react"; import { toast, ToastContainer } from "react-toastify"; import { injectStyle } from "react-toastify/dist/inject-style"; import Button from "../button"; import Input from "../input"; +import { useAuth } from "../../../context/AuthContext"; if (typeof window !== "undefined") { injectStyle(); } export default function EditProfile() { + const emailRef = useRef(null); + const { resetPassword } = useAuth(); const { t } = useTranslation("profile"); const router = useRouter(); @@ -34,6 +38,11 @@ export default function EditProfile() { .catch(() => {}); }; + const resetUserPassword = async () => { + await resetPassword(emailRef.current.value); + console.log("check your inbox for futher instructions"); + }; + return (
@@ -49,7 +58,18 @@ export default function EditProfile() { placeholder={t("name")} required /> - + + + + +
diff --git a/src/components/EditProfile/__test__/__snapshots__/EditProfile.test.jsx.snap b/src/components/EditProfile/__test__/__snapshots__/EditProfile.test.jsx.snap index 39f94d3..4364830 100644 --- a/src/components/EditProfile/__test__/__snapshots__/EditProfile.test.jsx.snap +++ b/src/components/EditProfile/__test__/__snapshots__/EditProfile.test.jsx.snap @@ -18,8 +18,8 @@ exports[`renders correctly 1`] = ` + + +
From 8a19cffbde7bd0952518d2d3ff8007139f840f0c Mon Sep 17 00:00:00 2001 From: Mohamed Hadri Date: Wed, 31 Aug 2022 02:54:04 +0300 Subject: [PATCH 2/3] feat: fixed an random error fix #97 --- data/products.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/products.json b/data/products.json index 529a283..4ab8455 100644 --- a/data/products.json +++ b/data/products.json @@ -596,7 +596,7 @@ "seller": { "id": 88888888, "displayName": "Nouh Rastanawi", - "email": "studentstoretemp@gmail.com", + "email": "studentstoretemp@gmaill.com", "image": "https://www.random-name-generator.com/images/faces/male-white/37.jpg?ezimgfmt=rs:148x143/rscb1/ng:webp/ngcb1" }, "requestedBuyers": [], From 2a56dc47e0afe67ca3c2bcc7b961c4af01b8d4e1 Mon Sep 17 00:00:00 2001 From: Mohamed Hadri Date: Wed, 31 Aug 2022 22:32:26 +0300 Subject: [PATCH 3/3] feat: added toast check for the email and removed unnecessary inputs resolve #97 --- src/components/EditProfile/EditProfile.jsx | 22 +++++++++++-------- .../__snapshots__/EditProfile.test.jsx.snap | 14 ------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/components/EditProfile/EditProfile.jsx b/src/components/EditProfile/EditProfile.jsx index b653131..51e3c3d 100644 --- a/src/components/EditProfile/EditProfile.jsx +++ b/src/components/EditProfile/EditProfile.jsx @@ -38,9 +38,18 @@ export default function EditProfile() { .catch(() => {}); }; - const resetUserPassword = async () => { - await resetPassword(emailRef.current.value); - console.log("check your inbox for futher instructions"); + const resetUserPassword = async (event) => { + event.preventDefault(); + + await resetPassword(emailRef.current.value) + .then(() => { + toast.success( + t( + "Check your inbox we Sent you a link to reset your password" + ) + "!" + ); + }) + .catch(() => {}); }; return ( @@ -70,11 +79,6 @@ export default function EditProfile() { ref={emailRef} /> - -
@@ -93,7 +97,7 @@ export default function EditProfile() {