doc: add user to useStateValue and render either login or logout and also create authHandle method
This commit is contained in:
1 parent
8df07b4289
commit
c9e71fb06f
1 file changed
+12
-3
+12
-3
@@ -3,9 +3,16 @@ import { Link } from "react-router-dom";
|
|||||||
import { Search, ShoppingCart } from "@material-ui/icons";
|
import { Search, ShoppingCart } from "@material-ui/icons";
|
||||||
import "./Header.css";
|
import "./Header.css";
|
||||||
import { useStateValue } from "../redux/StateProvider";
|
import { useStateValue } from "../redux/StateProvider";
|
||||||
|
import { auth } from "firebase";
|
||||||
|
|
||||||
function Header() {
|
function Header() {
|
||||||
const [{ basket }, dispatch] = useStateValue();
|
const [{ basket, user }] = useStateValue();
|
||||||
|
|
||||||
|
const authHandle = () => {
|
||||||
|
if (user) {
|
||||||
|
auth.signOut();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="header">
|
<header className="header">
|
||||||
@@ -23,9 +30,11 @@ function Header() {
|
|||||||
|
|
||||||
<nav className="header__nav">
|
<nav className="header__nav">
|
||||||
<Link to="/login">
|
<Link to="/login">
|
||||||
<section className="header__option">
|
<section onClick={authHandle} className="header__option">
|
||||||
<span className="header__optionLineOne">Hello</span>
|
<span className="header__optionLineOne">Hello</span>
|
||||||
<span className="header__optionLineTwo">Sign In</span>
|
<span className="header__optionLineTwo">
|
||||||
|
{user ? "Sign Out" : "Sign In"}
|
||||||
|
</span>
|
||||||
</section>
|
</section>
|
||||||
</Link>
|
</Link>
|
||||||
<section className="header__option">
|
<section className="header__option">
|
||||||
|
|||||||
Reference in new issue
Block a user