"use client" import Link from "next/link" import { useRouter } from "next/navigation" import { useState } from "react" import { authClient } from "@/lib/auth-client" import { useSession } from "@/components/SessionProvider" export default function LoginPage() { const router = useRouter() const { refreshSession } = useSession() const [error, setError] = useState("") const [loading, setLoading] = useState(false) async function handleSubmit(e: React.FormEvent) { e.preventDefault() console.log("Login form submitted via JavaScript handler") setLoading(true) setError("") const formData = new FormData(e.currentTarget) const email = formData.get("email") as string const password = formData.get("password") as string try { const result = await authClient.signIn.email({ email, password, }) if (result.error) { setError(result.error.message || "Failed to sign in") } else { // Refresh the session after successful login try { await refreshSession() } catch (err) { console.error("Failed to refresh session:", err) } // Use window.location for more reliable redirect in E2E tests window.location.href = "/admin" } } catch { setError("An unexpected error occurred") } finally { setLoading(false) } } return (

Sign in to your account

{error && (
{error}
)}
Create an account
Forgot password?
) }