"use client"; import { useSearchParams, useRouter } from "next/navigation"; import { authClient } from "@/lib/auth-client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Suspense, useState } from "react"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import Link from "next/link"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; function LoginForm() { const searchParams = useSearchParams(); const router = useRouter(); const redirectUrl = searchParams.get("redirect"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const handleLogin = async () => { setError(null); const { error } = await authClient.signIn.email({ email, password, }); if (error) { setError(error.message || "An unexpected error occurred."); return; } router.push(redirectUrl || "/"); }; return (
{error && ( Error {error} )}
setEmail(e.target.value)} />
setPassword(e.target.value)} />
); } export default function LoginPage() { return (
Login Enter your email and password to login. Loading...
}>
Don't have an account?{" "} Sign up
); }