"use client"; // Mark as a Client Component import { useState, useEffect } from "react"; import { signIn, useSession } from "next-auth/react"; import { useRouter, useSearchParams } 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 [isPasswordHovered, setIsPasswordHovered] = useState(false); // Add state for hover const router = useRouter(); const { data: session, status } = useSession(); const searchParams = useSearchParams(); useEffect(() => { // Removed redirection for authenticated users; do not auto-navigate away from login. // Retain error handling from search params. const errorParam = searchParams.get("error"); if (errorParam) { if (errorParam === "AuthError") { setError("Session expired. Please log in again."); } else { setError("Authentication failed. Please try again."); } } }, [searchParams]); const handleLogin = async (e) => { e.preventDefault(); if (!username || !password) { setError("Username and password are required"); return; } setIsLoading(true); setError(""); try { const result = await signIn("credentials", { redirect: false, username, password, callbackUrl: searchParams.get("callbackUrl") || "/team-selection", }); if (result?.error) { setError(result.error || "Login failed"); setIsLoading(false); } else if (result?.url) { router.push(result.url); } } catch (error) { console.error("Login error:", error); setError("Connection error. Please try again."); setIsLoading(false); } }; return (