'use client'; import { useState } from 'react'; import { useAuth } from '@/contexts/AuthContext'; import { useRouter } from 'next/navigation'; import { useEffect } from 'react'; import { LockClosedIcon } from '@heroicons/react/24/outline'; export default function LoginPage() { const [auth, setAuth] = useState(''); const [password, setPassword] = useState(''); const [localError, setLocalError] = useState(''); const { login, isLoading, error, token } = useAuth(); const router = useRouter(); useEffect(() => { if (token) { router.push('/admin/dashboard'); } }, [token, router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLocalError(''); if (!auth || !password) { setLocalError('Please fill in all fields'); return; } try { await login({ auth, password }); } catch (err) { // Error is handled by context } }; return (
برای ادامه وارد حساب کاربری خود شوید