diff --git a/main-website/app/api/me/route.ts b/main-website/app/api/me/route.ts new file mode 100644 index 0000000..965928a --- /dev/null +++ b/main-website/app/api/me/route.ts @@ -0,0 +1,8 @@ +import {NextRequest, NextResponse} from 'next/server' + +export function GET(req: NextRequest) { + const user = req.headers.get('x-user') ?? '' + const email = req.headers.get('x-email') ?? '' + + return NextResponse.json({user, email}) +} diff --git a/main-website/components/ProfileDropdown.tsx b/main-website/components/ProfileDropdown.tsx index 2a5308e..44c224c 100644 --- a/main-website/components/ProfileDropdown.tsx +++ b/main-website/components/ProfileDropdown.tsx @@ -1,35 +1,29 @@ 'use client' -import {useState, useRef, useEffect} from 'react' -import {useRouter} from 'next/navigation' +import { useEffect, useState } from 'react' +import { useRouter } from 'next/navigation' export default function ProfileDropdown() { const [open, setOpen] = useState(false) - const dropdownRef = useRef(null) + const [profile, setProfile] = useState<{ user?: string; email?: string }>({}) const router = useRouter() useEffect(() => { - const handleClickOutside = (event: MouseEvent) => { - if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { - setOpen(false) - } - } - - document.addEventListener('mousedown', handleClickOutside) - return () => document.removeEventListener('mousedown', handleClickOutside) + fetch('/api/me') + .then((res) => res.json()) + .then((data) => setProfile(data)) + .catch(() => setProfile({})) }, []) const handleLogout = async () => { - try { - await fetch('/logout', {method: 'POST'}) - router.push('/') // Or a dedicated post-logout landing page - } catch (e) { - console.error('Logout failed', e) - } + await fetch('/logout', { method: 'POST' }) + router.push('/') } + const name = profile.email || profile.user || 'Loading...' + return ( -
+
{open && ( -
+
+
+ {name} +