"use client"; import { useState } from "react"; import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import Link from "next/link"; export default function Login() { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); const handleLogin = async (e) => { e.preventDefault(); setIsLoading(true); setError(""); try { console.log("Attempting to sign in with:", username); const result = await signIn("credentials", { redirect: false, username, password, callbackUrl: `${window.location.origin}/team-selection`, }); console.log("Sign in result:", result); if (result?.error) { throw new Error(result.error); } if (result?.ok) { console.log("Sign in successful, redirecting..."); // Use router.push with { replace: true } to avoid history issues router.push("/team-selection", { replace: true }); return; } } catch (error) { console.error("Login error:", error); setError(error.message || "Failed to login. Please try again."); } finally { setIsLoading(false); } }; return (

Login to Treasure Hunt

setUsername(e.target.value)} required className="auth-input" />
setPassword(e.target.value)} required className="auth-input" />
{error &&
{error}
}
{/* Add separate div for register button with margin-top */}
{/* Update styles to include spacing between buttons */}
); }