"use client";
import { Suspense, useState } from "react";
import { signIn } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";
import Link from "next/link";
import { Activity, CheckCircle, Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";
export default function LoginPage() {
return (
);
}
function LoginForm() {
const router = useRouter();
const searchParams = useSearchParams();
const verified = searchParams.get("verified") === "true";
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const emailValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
const passwordValid = password.length >= 8;
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setError("");
if (!emailValid) {
setError("Please enter a valid email address");
return;
}
if (!passwordValid) {
setError("Password must be at least 8 characters");
return;
}
setLoading(true);
const result = await signIn("credentials", {
email,
password,
redirect: false,
});
if (result?.error) {
setError("Invalid email or password");
setLoading(false);
return;
}
router.push("/dashboard");
router.refresh();
}
return (
Welcome back
Sign in to your AgentLens account
{verified && (
Email verified! You can now sign in.
)}
Don't have an account?{" "}
Create one
);
}