diff --git a/frontend/src/components/navigations/Navbar.jsx b/frontend/src/components/navigations/Navbar.jsx index a31def6..dadb503 100644 --- a/frontend/src/components/navigations/Navbar.jsx +++ b/frontend/src/components/navigations/Navbar.jsx @@ -1,6 +1,8 @@ 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", @@ -10,6 +12,7 @@ const settings = { export function NavBar() { const Navigate = useNavigate(); const { isAuthenticated, setIsAuthenticated } = useAuth(); + const [profile_pic, setProfilePic] = useState(undefined); const logout = () => { apiUserLogout(); @@ -17,6 +20,25 @@ export function NavBar() { 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 (
@@ -32,14 +54,18 @@ export function NavBar() {
) : (
- -