'use client' import { useState } from 'react' import { useAuth } from '@/lib/auth/context' import { useRouter } from 'next/navigation' import { supabase } from '@/lib/supabase/client' export default function ApertureLogin() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState('') const { signInWithPassword } = useAuth() const router = useRouter() const handleLogin = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError('') try { const { error } = await signInWithPassword(email, password) if (error) { setError(error.message) } else { // Check user role from database const { data: { user } } = await supabase.auth.getUser() if (user) { const { data: staff } = await supabase .from('staff') .select('role') .eq('user_id', user.id) .single() if (staff && ['admin', 'manager', 'staff'].includes(staff.role)) { router.push('/aperture') } else { setError('Unauthorized access') await supabase.auth.signOut() } } } } catch (err) { setError('An error occurred') } finally { setLoading(false) } } return (

Aperture Login

Staff, Manager, or Admin access

setEmail(e.target.value)} className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="Email address" />
setPassword(e.target.value)} className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="Password" />
{error && (
{error}
)}
) }