import { useNavigate } from "react-router-dom"; import { apiUserLogout } from "src/api/AuthenticationApi"; import { useAuth } from "src/hooks/AuthHooks"; import { axiosInstance } from "src/api/AxiosConfig"; import { useEffect, useState } from "react"; const settings = { Profile: "/profile", Account: "/account", }; export function NavBar() { const Navigate = useNavigate(); const { isAuthenticated, setIsAuthenticated } = useAuth(); const [profile_pic, setProfilePic] = useState(undefined); const logout = () => { apiUserLogout(); setIsAuthenticated(false); Navigate("/"); }; useEffect(() => { const fetchUser = async () => { if (isAuthenticated) { try { const response = await axiosInstance.get("/user/data/"); const fetchedProfilePic = response.data.profile_pic; setProfilePic(fetchedProfilePic); } catch (error) { console.error("Error fetching user:", error); } } else { setProfilePic( "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" ); } }; fetchUser(); }, []); return (
TurTask
{/*
*/} {isAuthenticated ? (
) : (
)}
); }