mirror of
https://github.com/Priyatham-sai-chand/Locaft-backend.git
synced 2026-10-05 08:51:33 -07:00
32 lines
843 B
JavaScript
32 lines
843 B
JavaScript
|
|
import React, { useContext } from "react";
|
||
|
|
import { useHistory } from "react-router-dom";
|
||
|
|
import UserContext from "../../context/UserContext";
|
||
|
|
|
||
|
|
export default function AuthOptions() {
|
||
|
|
const { userData, setUserData } = useContext(UserContext);
|
||
|
|
|
||
|
|
const history = useHistory();
|
||
|
|
|
||
|
|
const register = () => history.push("/register");
|
||
|
|
const login = () => history.push("/login");
|
||
|
|
const logout = () => {
|
||
|
|
setUserData({
|
||
|
|
token: undefined,
|
||
|
|
user: undefined,
|
||
|
|
});
|
||
|
|
localStorage.setItem("auth-token", "");
|
||
|
|
};
|
||
|
|
|
||
|
|
return (
|
||
|
|
<nav className="auth-options">
|
||
|
|
{userData.user ? (
|
||
|
|
<button onClick={logout}>Log out</button>
|
||
|
|
) : (
|
||
|
|
<>
|
||
|
|
<button onClick={register}>Register</button>
|
||
|
|
<button onClick={login}>Log in</button>
|
||
|
|
</>
|
||
|
|
)}
|
||
|
|
</nav>
|
||
|
|
);
|
||
|
|
}
|