diff --git a/src/App.tsx b/src/App.tsx index 23854c1..e2c5a98 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -60,9 +60,6 @@ export default function App() { ); // Admin Login State - const [adminEmail, setAdminEmail] = useState(''); - const [adminPassword, setAdminPassword] = useState(''); - const [showAdminPassword, setShowAdminPassword] = useState(false); const [adminAuthLoading, setAdminAuthLoading] = useState(false); const [adminAuthError, setAdminAuthError] = useState(null); @@ -275,14 +272,13 @@ export default function App() { }; // Auth Handlers - const handleAdminLogin = async (e: React.FormEvent) => { - e.preventDefault(); + const handleAdminLogin = async (credentials: { email: string; password: string }) => { setAdminAuthLoading(true); setAdminAuthError(null); try { const res = await axios.post(`${API_BASE}/api/auth/login`, { - email: adminEmail, - password: adminPassword, + email: credentials.email, + password: credentials.password, }); const token = res.data.access_token; localStorage.setItem('access_token', token); @@ -299,6 +295,7 @@ export default function App() { localStorage.removeItem('access_token'); setUserToken(null); setLoggedInUser(null); + setAdminAuthError(null); }; // Force Sync Gateway Handler @@ -937,17 +934,12 @@ export default function App() { if (!loggedInUser || !isAdmin) { return ( setShowAdminPassword(!showAdminPassword)} onSubmit={handleAdminLogin} + onLogout={handleLogout} /> ); } diff --git a/src/components/auth/AdminLoginForm.tsx b/src/components/auth/AdminLoginForm.tsx index f1accd8..1ba66a3 100644 --- a/src/components/auth/AdminLoginForm.tsx +++ b/src/components/auth/AdminLoginForm.tsx @@ -1,33 +1,32 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Sparkles, AlertCircle, Shield, Eye, EyeOff } from 'lucide-react'; interface AdminLoginFormProps { - email: string; - password: string; - showPassword: boolean; loading: boolean; error: string | null; loggedInUser: any; isAdmin: boolean; - onEmailChange: (v: string) => void; - onPasswordChange: (v: string) => void; - onToggleShowPassword: () => void; - onSubmit: (e: React.FormEvent) => void; + onSubmit: (credentials: { email: string; password: string }) => void; + onLogout?: () => void; } export const AdminLoginForm: React.FC = ({ - email, - password, - showPassword, loading, error, loggedInUser, isAdmin, - onEmailChange, - onPasswordChange, - onToggleShowPassword, onSubmit, + onLogout, }) => { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [showPassword, setShowPassword] = useState(false); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + onSubmit({ email, password }); + }; + return (
@@ -47,21 +46,33 @@ export const AdminLoginForm: React.FC = ({ )} {loggedInUser && !isAdmin && ( -
- - Account {loggedInUser.email} lacks administrative privileges. +
+
+ + Account {loggedInUser.email} lacks administrative privileges. +
+ {onLogout && ( + + )}
)} -
+
onEmailChange(e.target.value)} + onChange={(e) => setEmail(e.target.value)} placeholder="admin@acupedia.in" + autoComplete="username" className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500" />
@@ -73,13 +84,14 @@ export const AdminLoginForm: React.FC = ({ type={showPassword ? 'text' : 'password'} required value={password} - onChange={(e) => onPasswordChange(e.target.value)} + onChange={(e) => setPassword(e.target.value)} placeholder="••••••••" + autoComplete="current-password" className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500" />