// components/auth/login-form.tsx 'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' export function LoginForm() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const router = useRouter() async function handleSubmit(e: React.FormEvent) { e.preventDefault() setLoading(true) setError(null) const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }) if (!res.ok) { const data = await res.json() setError(data.error ?? 'Login failed') setLoading(false) return } // Middleware will redirect to correct role home based on JWT router.push('/') router.refresh() } return (

IMS

HSE Incident Management

{error && (

{error}

)} setEmail(e.target.value)} required autoComplete="email" className="border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" /> setPassword(e.target.value)} required autoComplete="current-password" className="border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" />

Forgot password?

) }