From 9b300aa8abef57bbf8b15258e6f571207ccaff68 Mon Sep 17 00:00:00 2001 From: anwesha Date: Mon, 20 May 2024 17:05:14 -0400 Subject: [PATCH] refac:some fuctionality issue --- src/App.js | 2 +- src/Components/Navbar/Navbar.jsx | 15 ++++++--------- src/Pages/LoginSignup.jsx | 17 +++++++++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/App.js b/src/App.js index 0eb7d30..214748f 100644 --- a/src/App.js +++ b/src/App.js @@ -19,7 +19,7 @@ import Collections from "./Pages/Collections"; import Offers from "./Pages/Offers"; function App() { const { theme } = useContext(ShopContext); - const user = localStorage.getItem("email") + const user = localStorage.getItem("signinemail") return (
diff --git a/src/Components/Navbar/Navbar.jsx b/src/Components/Navbar/Navbar.jsx index 3f2eb30..0a54443 100644 --- a/src/Components/Navbar/Navbar.jsx +++ b/src/Components/Navbar/Navbar.jsx @@ -5,7 +5,7 @@ import cart_icon from '../Assets/cart_icon.png'; import cart_icon_dark from '../Assets/cart_icon_dark.png'; import moonIcon from '../Assets/dark_mode.png'; import sunIcon from '../Assets/light_mode.png'; -import { Link } from 'react-router-dom'; +import {Link, useNavigate} from 'react-router-dom'; import { ShopContext } from '../../Context/ShopContext'; const Navbar = () => { @@ -26,13 +26,13 @@ const Navbar = () => { dnav.classList.remove("dark"); } }; + const navigate = useNavigate() - const credentials = localStorage.getItem("email") + const credentials = localStorage.getItem("signinemail") const LogOutClick = () => { - localStorage.setItem("name " , "") - localStorage.setItem("email " , "") - localStorage.setItem("password " , "") + localStorage.setItem("signinemail","") + navigate("/login") } return ( @@ -62,10 +62,7 @@ const Navbar = () => {
- {credentials !== ""? : - - - } + {credentials !== "" && }
{getTotalCartItems()}
diff --git a/src/Pages/LoginSignup.jsx b/src/Pages/LoginSignup.jsx index ed9926e..8e1a940 100644 --- a/src/Pages/LoginSignup.jsx +++ b/src/Pages/LoginSignup.jsx @@ -21,20 +21,29 @@ const LoginSignup = () => { const SignUp = (e) => { e.preventDefault() - localStorage.setItem("name",formData.name) - localStorage.setItem("email",formData.email) - localStorage.setItem("password",formData.password) - navigate("/") + const email = localStorage.getItem("email") + if(formData.email === email){ + alert("already signed In with this account") + } + else{ + localStorage.setItem("name",formData.name) + localStorage.setItem("email",formData.email) + localStorage.setItem("password",formData.password) + localStorage.setItem("signinemail",formData.email ) + navigate("/") + } } function SignIn(e){ e.preventDefault() const email = localStorage.getItem("email") const password = localStorage.getItem("password") + if (password !== formData.password || email !== formData.email){ alert("Wrong credentials") } else { + localStorage.setItem("signinemail",formData.email ) navigate("/") } }