import { useState } from 'react' import { useNavigate, Navigate } from 'react-router-dom' import { useForm } from 'react-hook-form' import { Mail, Lock, Eye, EyeOff, Shield } from 'lucide-react' import { QRCodeSVG } from 'qrcode.react' import toast from 'react-hot-toast' import { Button } from '@/components/ui/Button' import { Input } from '@/components/ui/Input' import { Label } from '@/components/ui/Label' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/Card' import { useAuthStore } from '@/store/auth.store' import { getErrorMessage } from '@/api/client' interface LoginFormValues { email: string password: string totp_code?: string } type LoginStep = 'credentials' | 'totp' export function LoginPage() { const navigate = useNavigate() const { isAuthenticated, login, isLoading } = useAuthStore() const [step, setStep] = useState('credentials') const [showPassword, setShowPassword] = useState(false) const { register, handleSubmit, getValues, formState: { errors }, } = useForm() // Se già autenticato, vai all'inbox if (isAuthenticated) { return } const onSubmit = async (data: LoginFormValues) => { try { await login({ email: data.email, password: data.password, totp_code: data.totp_code, }) toast.success('Accesso effettuato con successo') navigate('/inbox', { replace: true }) } catch (error) { const msg = getErrorMessage(error) // Se l'errore indica che serve il TOTP, passa al secondo step if (msg.toLowerCase().includes('totp') || msg.toLowerCase().includes('otp') || msg.toLowerCase().includes('2fa')) { setStep('totp') return } toast.error(msg) } } return (
{/* Logo */}
PF

PecFlow

Gestore PEC SaaS

{step === 'credentials' ? ( <> Accedi Inserisci le tue credenziali per continuare
{errors.email && (

{errors.email.message}

)}
{errors.password && (

{errors.password.message}

)}
) : ( <>
Verifica 2FA
Inserisci il codice a 6 cifre dall'app autenticatore per{' '} {getValues('email')}
{errors.totp_code && (

{errors.totp_code.message}

)}
)}

PecFlow v1.0 – Piattaforma gestione PEC certificata

) }