import { supabase } from '../supabaseClient'; import React, { useState } from 'react'; import { motion } from 'framer-motion'; // --- SVG Icon Components --- const UserIcon = () => (); const LockIcon = () => (); const SpinnerIcon = () => ; export default function AdminLogin({ onNavigate }) { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleAdminLogin = async (e) => { e.preventDefault(); setError(''); if (!email.trim() || !password) { setError('Email and password are required.'); return; } setLoading(true); try { // 1. Authenticate const { data: { user }, error: authError } = await supabase.auth.signInWithPassword({ email: email, password: password, }); if (authError) throw authError; if (!user) throw new Error("Login failed."); // 2. Check Role const { data: roleData, error: roleError } = await supabase .from('user_roles') .select('role') .eq('user_id', user.id) .single(); if (roleError && roleError.code !== 'PGRST116') { throw new Error("Could not verify user role."); } // 3. Admin Check // Accepts 'admin' or 'recruiter' based on your previous logic if (roleData && (roleData.role === 'admin' || roleData.role === 'recruiter')) { if (typeof onNavigate === 'function') { onNavigate('admin-dashboard'); } } else { await supabase.auth.signOut(); throw new Error("Access Denied. Authorized personnel only."); } } catch (err) { setError(err.message); } finally { setLoading(false); } }; return (
{/* --- 🔴 FIXED BACK BUTTON --- */} {/* Background Shapes */} <>

Admin Portal

Manage CV submissions and applications

setEmail(e.target.value)} disabled={loading} placeholder="admin@email.com" style={{ width: '100%', padding: '0.75rem 1rem 0.75rem 2.5rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid rgba(239, 68, 68, 0.3)`, borderRadius: '0.5rem', color: 'white', boxSizing: 'border-box' }} />
setPassword(e.target.value)} disabled={loading} placeholder="Password" style={{ width: '100%', padding: '0.75rem 1rem 0.75rem 2.5rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid rgba(239, 68, 68, 0.3)`, borderRadius: '0.5rem', color: 'white', boxSizing: 'border-box' }} />
{error &&

{error}

} {loading && } {loading ? 'Verifying...' : 'Continue'}
); }