"use client"; import { useRouter } from "next/navigation"; import { signIn } 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 { Separator } from "@/components/ui/separator"; import Link from "next/link"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { ArrowLeft, Loader2 } from "lucide-react"; import { GoogleIcon } from "@/components/icons"; function LoginForm() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [isEmailLoading, setIsEmailLoading] = useState(false); const [isGoogleLoading, setIsGoogleLoading] = useState(false); const handleLogin = async () => { setError(null); setIsEmailLoading(true); const { error } = await signIn.email({ email, password, }); if (error) { setError(error.message || "An unexpected error occurred."); setIsEmailLoading(false); return; } router.push("/editor"); }; const handleGoogleLogin = async () => { setError(null); setIsGoogleLoading(true); try { await signIn.social({ provider: "google", }); router.push("/editor"); } catch (error) { setError("Failed to sign in with Google. Please try again."); setIsGoogleLoading(false); } }; const isAnyLoading = isEmailLoading || isGoogleLoading; return (
{error && ( Error {error} )}
Or continue with
setEmail(e.target.value)} disabled={isAnyLoading} className="h-11" />
setPassword(e.target.value)} disabled={isAnyLoading} className="h-11" />
); } export default function LoginPage() { const router = useRouter(); return (
Welcome back Sign in to your account to continue
} >
Don't have an account?{" "} Sign up
); }