From 057d57c3d3620c73b3834b13863b47789c6e036c Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Wed, 15 Nov 2023 13:30:24 -0600 Subject: [PATCH] Use session data for sidebar. No need for another query --- components/DesktopSidebar/UserIcon.tsx | 23 +++-------------------- pages/index.tsx | 1 - 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/components/DesktopSidebar/UserIcon.tsx b/components/DesktopSidebar/UserIcon.tsx index 7909cb5..734bfd9 100644 --- a/components/DesktopSidebar/UserIcon.tsx +++ b/components/DesktopSidebar/UserIcon.tsx @@ -8,27 +8,10 @@ import { UserIconContainer, } from '@/styles/components/Sidebar/userIcon.styles'; import { Media } from '@/lib/media'; -import { QueriedUserData } from 'bookem-shared/src/types/database'; +import { useSession } from 'next-auth/react'; export const UserIcon = () => { - const [userData, setUserData] = useState(null); - const [error, setError] = useState(); - - useEffect(() => { - try { - fetchData('/api/users/') - .then(data => { - if (data != null) { - console.log('Fetched data:', data); - setUserData(data); - } - }) - .catch(err => setError(err)); - } catch (error) { - setError(new Error('Error fetching user data')); - console.error('Error fetching user data:', error); - } - }, []); + const { data: session } = useSession(); return ( @@ -42,7 +25,7 @@ export const UserIcon = () => { - {userData !== null && userData.name} + {session?.user && session.user.name} ); }; diff --git a/pages/index.tsx b/pages/index.tsx index cf2e242..ab19547 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -11,7 +11,6 @@ const HomePage = () => { try { fetchData('/api/users/') .then(data => { - console.log('Fetched data:', data); setUserData(data); }) .catch(err => setError(err));