import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../context/useAuth'; import { ShieldCheck, Lock, User, ArrowRight, Sparkles, Eye, EyeOff } from 'lucide-react'; /* * There is exactly one interactive account: `admin`. * * This screen used to offer an Admin/User tab pair, which was always more * suggestion than control - the server assigns the role from the account the * password belongs to (see AuthContext.login), so the tab never affected the * outcome. With the `user` account switched off in the backend config, the * tabs would have offered a sign-in that could only ever fail, so they are gone * and this is a single admin form. */ export function LoginPage() { const navigate = useNavigate(); const { login } = useAuth(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleFormSubmit = async (e) => { e.preventDefault(); setError(''); if (!username.trim() || !password.trim()) { setError('Please enter both username and password.'); return; } setLoading(true); try { const user = await login(username, password); setLoading(false); // Only `admin` can sign in, and every route is admin-only, so there is // one destination. Sending a non-admin to /login instead would loop. navigate(user.role === 'admin' ? '/admin' : '/login'); } catch (err) { setLoading(false); // Surface the server's own message: it distinguishes bad credentials // from the lockout after repeated failures, which a generic string hides. setError(err?.message || 'Login failed. Check your username and password.'); } }; return (
Please enter your username and password to sign in
Powered by pgvector RAG Model & Multi-Store Nutrition Intelligence Engine