diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 394cd6e..5bce44d 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,30 +1,28 @@ import useWindowDimensions from "../hooks/WindowDimensionsHook.tsx"; import "../assets/css/Header.css" -import {Link, useNavigate, useLocation} from "react-router-dom"; +import {Link, useNavigate} from "react-router-dom"; import {auth} from "../utils/firebase.ts"; +import {useState} from "react"; +import {User} from "firebase/auth"; -interface Props { - user?: string; - children?: React.ReactNode; -} - -export function Header({ user }: Props) { +export function Header() { const { width, height } = useWindowDimensions(); const aspect_ratio = (width == 0? 1 : width) / (height == 0? 1 : height); const use_narrow = aspect_ratio < 0.7; - const currentUser = auth.currentUser?.displayName?? ""; + const [userName, setUserName] = useState(null); + auth.onAuthStateChanged((new_user: User | null) => { + if (new_user === null) { setUserName(null); } + else { setUserName(new_user?.displayName) } + }); const navigate = useNavigate(); - const location = useLocation(); - const handleLogout = () => { - auth.signOut(); + const handleLogout = async () => { + await auth.signOut(); navigate("/", { replace: true }); }; - const isIndexPage = location.pathname === "/"; - return (
{/* App Name reloads home page */} @@ -35,16 +33,16 @@ export function Header({ user }: Props) { {/* Pages */}