diff --git a/src/App.tsx b/src/App.tsx index de0f0ba..264db68 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import { Route, Routes, useLocation } from 'react-router-dom'; import { AdminDashboard } from './components/AdminDashboard/AdminDashboard'; import { AdminSettingsMaster } from './components/AdminSettings/AdminSettingsMaster'; import ForgotPassword from './components/Authentication/ForgotPassword'; -import Login from './components/Authentication/Login'; +import { Login } from './components/Authentication/Login'; import { BusinessDashboard } from './components/BusinessDashboard/BusinessDashboard'; import { BusinessDonationHistory } from './components/BusinessDonationHistory/BusinessDonationHistory'; import { ViewBusinessDonationHistory } from './components/BusinessDonationHistory/ViewBusinessDonationHistory/ViewBusinessDonationHistory'; @@ -55,7 +55,7 @@ const App = () => { } /> } /> } /> - } /> + } /> } /> { +export const Login = () => { // React states for input fields const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const { login } = useAuth(); - // TODO: Setup Error Alert - // eslint-disable-next-line no-unused-vars - const [error, setError] = useState(''); + const { backend } = useBackend(); + const [loading, setLoading] = useState(false); const navigate = useNavigate(); const toast = useToast(); - const handleSubmit = async (e) => { + const handleSubmit = async (e: MouseEvent) => { e.preventDefault(); try { - setError(''); setLoading(true); - await login({ email, password }); - if (isAdmin) { + const userCredential = await login({ email, password }); + + const response = await backend.get(`/adminUser/${userCredential.user.email}`); + const user = response.data.at(0); + + if (user.name) { navigate('/AdminDashboard'); } else { navigate('/BusinessDashboard'); @@ -81,14 +83,15 @@ const Login = ({ isAdmin }) => { setPassword(e.target.value)} /> - Forgot Password? - +