"use client"; import { useSession, signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { FaSpinner } from "react-icons/fa"; // For a spinner icon import { Banner } from "@/components/Banner"; import { Navbar } from "@/components/Navbar"; const DashboardPage = () => { const { data: session, status } = useSession(); const router = useRouter(); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [guilds, setGuilds] = useState([]); // Update type as needed useEffect(() => { if (status === "loading") return; if (status === "unauthenticated") { signIn(); } else { console.log("Session Data:", session); // Log session data const fetchGuilds = async () => { try { const response = await fetch('/api/user/guilds'); console.log("API Response Status:", response.status); // Log the response status if (!response.ok) { throw new Error(`Network response was not ok: ${response.statusText}`); } const data = await response.json(); console.log('Guild data:', data); // Log the guild data setGuilds(data.userGuilds || []); // Set guild data in state } catch (error) { console.error('Error fetching guilds:', error); setError('Failed to load guild data.'); } finally { setLoading(false); } }; fetchGuilds(); } }, [status, router, session]); if (status === "loading" || loading) { return (
Loading...
); } if (status === "unauthenticated") { return (

You need to sign in to access the dashboard.

); } return (
User Avatar

Welcome, {session?.user?.name}!

ID: {session?.user?.id}

{error &&

{error}

}
); }; export default DashboardPage;