diff --git a/frontend/src/components/Topbar.jsx b/frontend/src/components/Topbar.jsx index b81d72a..fb55ea7 100644 --- a/frontend/src/components/Topbar.jsx +++ b/frontend/src/components/Topbar.jsx @@ -1,4 +1,18 @@ +import { useContext, useState } from 'react'; +import { AuthContext } from '../App.jsx'; +import { logout as apiLogout } from '../api.js'; + export default function Topbar({ archives, archiveId, onArchiveChange, view, onViewChange, onCaptureClick }) { + const { currentUser, setCurrentUser } = useContext(AuthContext) ?? {}; + const [loggingOut, setLoggingOut] = useState(false); + + async function handleLogout() { + setLoggingOut(true); + await apiLogout(); + setCurrentUser(null); + window.location.reload(); + } + return (
Archivr
@@ -15,6 +29,14 @@ export default function Topbar({ archives, archiveId, onArchiveChange, view, onV ))} + {currentUser && ( +
+ {currentUser.username} + +
+ )}
- ) + ); }