Compare commits

..

2 Commits

2 changed files with 38 additions and 34 deletions

View File

@ -60,9 +60,6 @@ export default function App() {
); );
// Admin Login State // Admin Login State
const [adminEmail, setAdminEmail] = useState('');
const [adminPassword, setAdminPassword] = useState('');
const [showAdminPassword, setShowAdminPassword] = useState(false);
const [adminAuthLoading, setAdminAuthLoading] = useState(false); const [adminAuthLoading, setAdminAuthLoading] = useState(false);
const [adminAuthError, setAdminAuthError] = useState<string | null>(null); const [adminAuthError, setAdminAuthError] = useState<string | null>(null);
@ -275,14 +272,13 @@ export default function App() {
}; };
// Auth Handlers // Auth Handlers
const handleAdminLogin = async (e: React.FormEvent) => { const handleAdminLogin = async (credentials: { email: string; password: string }) => {
e.preventDefault();
setAdminAuthLoading(true); setAdminAuthLoading(true);
setAdminAuthError(null); setAdminAuthError(null);
try { try {
const res = await axios.post(`${API_BASE}/api/auth/login`, { const res = await axios.post(`${API_BASE}/api/auth/login`, {
email: adminEmail, email: credentials.email,
password: adminPassword, password: credentials.password,
}); });
const token = res.data.access_token; const token = res.data.access_token;
localStorage.setItem('access_token', token); localStorage.setItem('access_token', token);
@ -299,6 +295,7 @@ export default function App() {
localStorage.removeItem('access_token'); localStorage.removeItem('access_token');
setUserToken(null); setUserToken(null);
setLoggedInUser(null); setLoggedInUser(null);
setAdminAuthError(null);
}; };
// Force Sync Gateway Handler // Force Sync Gateway Handler
@ -937,17 +934,12 @@ export default function App() {
if (!loggedInUser || !isAdmin) { if (!loggedInUser || !isAdmin) {
return ( return (
<AdminLoginForm <AdminLoginForm
email={adminEmail}
password={adminPassword}
showPassword={showAdminPassword}
loading={adminAuthLoading} loading={adminAuthLoading}
error={adminAuthError} error={adminAuthError}
loggedInUser={loggedInUser} loggedInUser={loggedInUser}
isAdmin={isAdmin} isAdmin={isAdmin}
onEmailChange={setAdminEmail}
onPasswordChange={setAdminPassword}
onToggleShowPassword={() => setShowAdminPassword(!showAdminPassword)}
onSubmit={handleAdminLogin} onSubmit={handleAdminLogin}
onLogout={handleLogout}
/> />
); );
} }

View File

@ -1,33 +1,32 @@
import React from 'react'; import React, { useState } from 'react';
import { Sparkles, AlertCircle, Shield, Eye, EyeOff } from 'lucide-react'; import { Sparkles, AlertCircle, Shield, Eye, EyeOff } from 'lucide-react';
interface AdminLoginFormProps { interface AdminLoginFormProps {
email: string;
password: string;
showPassword: boolean;
loading: boolean; loading: boolean;
error: string | null; error: string | null;
loggedInUser: any; loggedInUser: any;
isAdmin: boolean; isAdmin: boolean;
onEmailChange: (v: string) => void; onSubmit: (credentials: { email: string; password: string }) => void;
onPasswordChange: (v: string) => void; onLogout?: () => void;
onToggleShowPassword: () => void;
onSubmit: (e: React.FormEvent) => void;
} }
export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({ export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
email,
password,
showPassword,
loading, loading,
error, error,
loggedInUser, loggedInUser,
isAdmin, isAdmin,
onEmailChange,
onPasswordChange,
onToggleShowPassword,
onSubmit, 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 ( return (
<div className="min-h-screen bg-[#08080C] text-slate-100 flex items-center justify-center p-4 selection:bg-indigo-500 selection:text-white"> <div className="min-h-screen bg-[#08080C] text-slate-100 flex items-center justify-center p-4 selection:bg-indigo-500 selection:text-white">
<div className="w-full max-w-md bg-slate-900/90 border border-slate-800 rounded-3xl p-8 shadow-2xl backdrop-blur-xl space-y-6"> <div className="w-full max-w-md bg-slate-900/90 border border-slate-800 rounded-3xl p-8 shadow-2xl backdrop-blur-xl space-y-6">
@ -47,21 +46,33 @@ export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
)} )}
{loggedInUser && !isAdmin && ( {loggedInUser && !isAdmin && (
<div className="p-3 bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs rounded-xl font-bold flex items-center gap-2"> <div className="p-3 bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs rounded-xl font-bold flex flex-col gap-2">
<div className="flex items-center gap-2">
<Shield className="h-4 w-4 shrink-0" /> <Shield className="h-4 w-4 shrink-0" />
<span>Account {loggedInUser.email} lacks administrative privileges.</span> <span>Account {loggedInUser.email} lacks administrative privileges.</span>
</div> </div>
{onLogout && (
<button
type="button"
onClick={onLogout}
className="text-[11px] text-amber-300 hover:text-white underline text-left cursor-pointer"
>
Log out
</button>
)}
</div>
)} )}
<form onSubmit={onSubmit} className="space-y-4"> <form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-1"> <div className="space-y-1">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-400">Admin Email</label> <label className="text-[10px] uppercase font-black tracking-wider text-slate-400">Admin Email</label>
<input <input
type="email" type="email"
required required
value={email} value={email}
onChange={(e) => onEmailChange(e.target.value)} onChange={(e) => setEmail(e.target.value)}
placeholder="admin@acupedia.in" 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" 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"
/> />
</div> </div>
@ -73,13 +84,14 @@ export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
type={showPassword ? 'text' : 'password'} type={showPassword ? 'text' : 'password'}
required required
value={password} value={password}
onChange={(e) => onPasswordChange(e.target.value)} onChange={(e) => setPassword(e.target.value)}
placeholder="••••••••" 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" 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"
/> />
<button <button
type="button" type="button"
onClick={onToggleShowPassword} onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-3 text-slate-400 hover:text-white cursor-pointer" className="absolute right-3 top-3 text-slate-400 hover:text-white cursor-pointer"
> >
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />} {showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}