Compare commits
No commits in common. "feb878d314c18b8a91d80c7cdb512acf7f66da16" and "63cd8078f6e576e2b415ebeb01e866d5597db7b3" have entirely different histories.
feb878d314
...
63cd8078f6
18
src/App.tsx
18
src/App.tsx
|
|
@ -60,6 +60,9 @@ 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);
|
||||||
|
|
||||||
|
|
@ -272,13 +275,14 @@ export default function App() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Auth Handlers
|
// Auth Handlers
|
||||||
const handleAdminLogin = async (credentials: { email: string; password: string }) => {
|
const handleAdminLogin = async (e: React.FormEvent) => {
|
||||||
|
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: credentials.email,
|
email: adminEmail,
|
||||||
password: credentials.password,
|
password: adminPassword,
|
||||||
});
|
});
|
||||||
const token = res.data.access_token;
|
const token = res.data.access_token;
|
||||||
localStorage.setItem('access_token', token);
|
localStorage.setItem('access_token', token);
|
||||||
|
|
@ -295,7 +299,6 @@ 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
|
||||||
|
|
@ -934,12 +937,17 @@ 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}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,33 @@
|
||||||
import React, { useState } from 'react';
|
import React 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;
|
||||||
onSubmit: (credentials: { email: string; password: string }) => void;
|
onEmailChange: (v: string) => void;
|
||||||
onLogout?: () => void;
|
onPasswordChange: (v: string) => 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">
|
||||||
|
|
@ -46,33 +47,21 @@ 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 flex-col 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 items-center 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={handleSubmit} className="space-y-4">
|
<form onSubmit={onSubmit} 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) => setEmail(e.target.value)}
|
onChange={(e) => onEmailChange(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>
|
||||||
|
|
@ -84,14 +73,13 @@ export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
|
||||||
type={showPassword ? 'text' : 'password'}
|
type={showPassword ? 'text' : 'password'}
|
||||||
required
|
required
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => onPasswordChange(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={() => setShowPassword(!showPassword)}
|
onClick={onToggleShowPassword}
|
||||||
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" />}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue