'use client'; import { useState } from 'react'; import { useTranslations } from 'next-intl'; import { Link, useRouter } from '@/i18n/navigation'; import Image from 'next/image'; import { ShieldCheck } from 'lucide-react'; import { login as apiLogin, getCurrentUser, logout as apiLogout } from '@/lib/api/auth'; import { useAuth } from '@/lib/context/auth-context'; export default function AdminLoginPage() { const t = useTranslations('admin.login'); const router = useRouter(); const { refreshUser } = useAuth(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { await apiLogin({ email, password, rememberMe: false }); const me = await getCurrentUser(); if (me.role !== 'ADMIN') { // Valid credentials but not an administrator — drop the session. await apiLogout(); setError(t('notAdmin')); return; } await refreshUser(); router.replace('/admin'); } catch (err) { setError(t('error')); } finally { setIsLoading(false); } }; return (
Xpeditis
{t('badge')}

{t('title')}

{t('subtitle')}

{error && (

{error}

)}
setEmail(e.target.value)} className="input w-full" placeholder={t('emailPlaceholder')} autoComplete="email" disabled={isLoading} required />
setPassword(e.target.value)} className="input w-full" placeholder={t('passwordPlaceholder')} autoComplete="current-password" disabled={isLoading} required />
{t('backToApp')}
); }