"use client";
import Link from "next/link";
import React from "react";
import { usePathname } from "next/navigation";
import { useBaseRoms } from "@/contexts/BaseRomContext";
import { useAuthContext } from "@/contexts/AuthContext";
import { createClient } from "@/utils/supabase/client";
import Avatar from "@/components/Account/Avatar";
function NavLink({ href, label, className = "" }: { href: string; label: React.ReactNode; className?: string }) {
const pathname = usePathname();
const isActive = pathname === href;
return (
{label}
);
}
export default function Header() {
const { countReady } = useBaseRoms();
const { user } = useAuthContext();
const pathname = usePathname();
const supabase = createClient();
const [isAuthenticated, setIsAuthenticated] = React.useState(false);
const [userId, setUserId] = React.useState(null);
const [avatarUrl, setAvatarUrl] = React.useState(null);
React.useEffect(() => {
let isMounted = true;
(async () => {
const { data } = await supabase.auth.getUser();
if (!isMounted) return;
const authed = Boolean(data.user);
setIsAuthenticated(authed);
setUserId(data.user?.id ?? null);
// Best-effort fetch profile avatar_url for header avatar
if (authed && data.user?.id) {
const { data: profile } = await supabase
.from('profiles')
.select('avatar_url')
.eq('id', data.user.id)
.single();
setAvatarUrl(profile?.avatar_url ?? null);
} else {
setAvatarUrl(null);
}
})();
return () => {
isMounted = false;
};
}, [supabase, user]);
return (
Hackdex
);
}