"use client"; import type React from "react"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { toast } from "sonner"; import { useAuth } from "@/hooks/use-auth"; import { loginUserApi } from "@/services/api-auth"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Icons } from "@/components/icons"; import { Checkbox } from "@/components/ui/checkbox"; import Image from "next/image"; export default function LoginPage() { const router = useRouter(); const { login } = useAuth(); const [isLoading, setIsLoading] = useState(false); const [formData, setFormData] = useState({ email: "", password: "", }); const [showPassword, setShowPassword] = useState(false); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { const response = await loginUserApi(formData); login(response.accessToken, { id: "user-123", username: "User", email: formData.email, emailVerified: true, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }); toast.success("Logged in successfully"); router.push("/todos"); } catch (error) { console.error("Login failed:", error); toast.error("Login failed. Please check your credentials."); } finally { setIsLoading(false); } }; return (
{/* Left side - Image */}
Background
TODO

Planning,
Organizing,

{/* Right side - Form */}
TODO {/* Back to website */}

Log in to your account

Don't have an account?{" "} Sign up

Forgot password?
Or continue with
); }