Skip to content

Commit

Permalink
Add a log in / out item to the top nav
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9smith committed Nov 21, 2024
1 parent 7f66fd0 commit f8df74a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions frontend/src/components/TopNav/TopNav.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import { Header, PageLayout } from "@primer/react";

import { Box, Header, PageLayout } from "@primer/react";
import { HomeIcon } from "@primer/octicons-react";
import { useNavigate } from "react-router";
import { authenticationService } from "../../services/authentication";

function TopNav() {
const navigate = useNavigate();
const logInOrOut = authenticationService.isAuthenticated() ? (
<Header.Item>
<Header.Link
as="div"
onClick={() => {
authenticationService.logout();
navigate("/login");
}}
>
Log out
</Header.Link>
</Header.Item>
) : (
<Header.Item>
<Header.Link href="/login">Log in</Header.Link>
</Header.Item>
);
return (
<PageLayout.Header divider={"none"}>
<Header>
Expand All @@ -12,9 +31,10 @@ function TopNav() {
<span>&nbsp;Home</span>
</Header.Link>
</Header.Item>
<Header.Item>
<Header.Item full>
<Header.Link href="/plan">Plan</Header.Link>
</Header.Item>
{logInOrOut}
</Header>
</PageLayout.Header>
);
Expand Down

0 comments on commit f8df74a

Please sign in to comment.