diff --git a/frontend/src/components/login/InitialLoginStep.tsx b/frontend/src/components/login/InitialLoginStep.tsx index 79b10bbdeb..77e83434e5 100644 --- a/frontend/src/components/login/InitialLoginStep.tsx +++ b/frontend/src/components/login/InitialLoginStep.tsx @@ -1,19 +1,65 @@ +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import attemptLogin from '@app/components/utilities/attemptLogin'; + +import Error from '../basic/Error'; // import { faGoogle } from '@fortawesome/free-brands-svg-icons'; // import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { Button } from '../v2'; +import { Button, Input } from '../v2'; export default function InitialLoginStep({ - setIsLoginWithEmail, + setStep, + email, + setEmail, + password, + setPassword, }: { - setIsLoginWithEmail: (value: boolean) => void; + setStep: (step: number) => void; + email: string; + setEmail: (email: string) => void; + password: string; + setPassword: (password: string) => void; }) { const router = useRouter(); const { t } = useTranslation(); + const [isLoading, setIsLoading] = useState(false); + const [loginError, setLoginError] = useState(false); + + const handleLogin = async () => { + try { + if (!email || !password) { + return; + } + + setIsLoading(true); + const isLoginSuccessful = await attemptLogin({ + email, + password, + }); + if (isLoginSuccessful && isLoginSuccessful.success) { + // case: login was successful + + if (isLoginSuccessful.mfaEnabled) { + // case: login requires MFA step + setStep(2); + setIsLoading(false); + return; + } + + // case: login does not require MFA step + router.push(`/dashboard/${localStorage.getItem('projectData.id')}`); + } + + } catch (err) { + setLoginError(true); + } + + setIsLoading(false); + } return