diff --git a/src/components/Admin/AdminRoute.js b/src/components/Admin/AdminRoute.js index 84da411..f22bfe1 100644 --- a/src/components/Admin/AdminRoute.js +++ b/src/components/Admin/AdminRoute.js @@ -1,13 +1,14 @@ // src/components/Admin/AdminRoute.jsx import React, { useState, useEffect } from 'react'; -import { Navigate } from 'react-router-dom'; import { supabase } from '../../lib/supabase'; import AdminPanel from './AdminPanel'; -// This component protects the admin route by checking authentication const AdminRoute = () => { const [isAuthenticated, setIsAuthenticated] = useState(null); const [isLoading, setIsLoading] = useState(true); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [authError, setAuthError] = useState(null); useEffect(() => { const checkAuth = async () => { @@ -36,6 +37,28 @@ const AdminRoute = () => { }; }, []); + const handleLogin = async (e) => { + e.preventDefault(); + setIsLoading(true); + setAuthError(null); + + try { + const { data, error } = await supabase.auth.signInWithPassword({ + email, + password + }); + + if (error) throw error; + + setIsAuthenticated(true); + } catch (error) { + console.error('Error logging in:', error); + setAuthError(error.message); + } finally { + setIsLoading(false); + } + }; + if (isLoading) { return (