mentorenwahl/docker/frontend/components/navbar.tsx

32 lines
677 B
TypeScript
Raw Normal View History

2022-02-02 14:38:36 +00:00
import Cookies from "js-cookie";
import Link from "next/link";
2022-02-02 20:54:14 +00:00
import Router from "next/router";
import * as cookieNames from "../lib/cookieNames";
2022-02-02 14:38:36 +00:00
function Navbar(): JSX.Element {
2022-02-02 20:54:14 +00:00
function handleLogout(event: Event): void {
2022-02-02 14:38:36 +00:00
event.preventDefault();
2022-02-02 20:54:14 +00:00
Cookies.remove(cookieNames.TOKEN);
Router.reload();
2022-02-02 14:38:36 +00:00
}
return (
<nav>
<ul>
<li>
{!!Cookies.get(cookieNames.TOKEN) ? (
2022-02-02 14:38:36 +00:00
<button onClick={handleLogout as any}>Logout</button>
) : (
<Link href="/login" passHref>
<button>Login</button>
</Link>
)}
</li>
</ul>
</nav>
);
}
export default Navbar;