"use client"; import { useState, useEffect } from "react"; import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import Link from "next/link"; const styles = { navbar: { position: "fixed", bottom: 0, width: "100%", backgroundColor: "#fff", borderTop: "1px solid #ccc", padding: "10px 0", textAlign: "center", }, }; export default function CreateTeam() { const { data: session, status } = useSession(); const [teamName, setTeamName] = useState(""); const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(true); const router = useRouter(); useEffect(() => { if (status === "authenticated") { if (session.user.teamId) { router.push(`/team/${session.user.teamId}`); } else { setIsLoading(false); } } else if (status === "unauthenticated") { router.push("/login"); } }, [status, session, router]); const handleCreateTeam = async (e) => { e.preventDefault(); setIsLoading(true); setError(""); try { const response = await fetch("/api/teams", { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", body: JSON.stringify({ name: teamName }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || "Failed to create team"); } // Navigate with the correct URL pattern for the page component console.log("Team created successfully with ID:", data.teamId); // Hard navigation to make sure we're going to the page component not the API route window.location.href = `/${data.teamId}`; } catch (err) { setError(err.message); setIsLoading(false); } }; if (isLoading) { return
Loading...
; } return (
Create Team

Create a New Team

setTeamName(e.target.value)} required className="auth-input" />
{error &&

{error}

}
🏠
📊
🏆
👤
); }