'use client' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { useRouter, useSearchParams } from 'next/navigation' import { useState } from 'react' import { useGlobal } from '@/providers/GlobalProvider' export function LoginForm({ className, ...props }: React.ComponentProps<'div'>) { const router = useRouter() const { setUser } = useGlobal() const [isLoading, setIsLoading] = useState(false) const searchParams = useSearchParams() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!isLoading) { const formData = new FormData(e.currentTarget) const email = String(formData.get('email')) const password = String(formData.get('password')) if (!email || !password) return setIsLoading(true) try { const loginReq = await fetch('/api/users/login', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email, password, }), }) const user = await loginReq.json() setUser(user.user) if (user.token) router.push(searchParams.get('redirectUrl') || '/') } catch (error) { console.error('Login failed:', error) } finally { setIsLoading(false) } } } return (
Welcome back Login to access your account
Don't have an account?{' '} Request Access
By clicking Login or Request Access, you agree to our{' '} Terms of Service and Privacy Policy.
) }