Skip to content

Commit

Permalink
refac:some fuctionality issue
Browse files Browse the repository at this point in the history
  • Loading branch information
anwesha authored and anwesha committed May 20, 2024
1 parent bdf7ba5 commit 9b300aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className={`${theme}_app`}>
<BrowserRouter>
Expand Down
15 changes: 6 additions & 9 deletions src/Components/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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 (
Expand Down Expand Up @@ -62,10 +62,7 @@ const Navbar = () => {
</li>
</ul>
<div className="nav-login-cart">
{credentials !== ""? <Link to='/login'><button onClick={LogOutClick} className='log_btn'>Log Out</button></Link> :
<Link to='/login'>
<button className='log_btn'>Login</button>
</Link>}
{credentials !== "" && <button onClick={LogOutClick} className='log_btn'>Log Out</button>}
<Link to='/cart'><img src={icon} alt="" className='cart' /></Link>
<div className="nav-cart-count">{getTotalCartItems()}</div>
<div className='dark_btn'>
Expand Down
17 changes: 13 additions & 4 deletions src/Pages/LoginSignup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
}
}
Expand Down

0 comments on commit 9b300aa

Please sign in to comment.