'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { useAuth } from '@/components/auth/AuthProvider'; export default function LoginPage() { const [isLogin, setIsLogin] = useState(true); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const { login, register } = useAuth(); const router = useRouter(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { if (isLogin) { await login(username, password); } else { await register(username, password); await login(username, password); } router.push('/'); } catch (err) { setError((err as Error).message || 'An error occurred'); } finally { setIsLoading(false); } }; return (
Synculous

Synculous

{isLogin ? 'Welcome back!' : 'Create your account'}

{error && (
{error}
)}
setUsername(e.target.value)} className="w-full px-4 py-3 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 outline-none transition" placeholder="Enter your username" required />
setPassword(e.target.value)} className="w-full px-4 py-3 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 outline-none transition" placeholder="Enter your password" required />
); }