"use client"; import { useEffect, useState } from "react"; interface User { email: string; } export function useAuth() { const [user, setUser] = useState(null); const [isLoaded, setIsLoaded] = useState(false); useEffect(() => { fetch("/api/auth/me") .then((r) => { if (!r.ok) throw new Error("Unauthorized"); return r.json(); }) .then((json) => setUser({ email: json.email })) .catch(() => setUser(null)) .finally(() => setIsLoaded(true)); }, []); return { user, isLoaded }; }