import { FormEvent, useState } from "react"; import { useTranslation } from "react-i18next"; import Link from "next/link"; import { useRouter } from "next/router"; import { faGithub,faGoogle } from "@fortawesome/free-brands-svg-icons"; import { faLock } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import axios from "axios" import Error from "@app/components/basic/Error"; import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider"; import attemptCliLogin from "@app/components/utilities/attemptCliLogin"; import attemptLogin from "@app/components/utilities/attemptLogin"; import { Button, Input } from "@app/components/v2"; import { fetchOrganizations } from "@app/hooks/api/organization/queries"; import { useFetchServerStatus } from "@app/hooks/api/serverDetails"; type Props = { setStep: (step: number) => void; email: string; setEmail: (email: string) => void; password: string; setPassword: (email: string) => void; } export const InitialStep = ({ setStep, email, setEmail, password, setPassword }: Props) => { const router = useRouter(); const { createNotification } = useNotificationContext(); const { t } = useTranslation(); const [isLoading, setIsLoading] = useState(false); const [loginError, setLoginError] = useState(false); const { data: serverDetails } = useFetchServerStatus(); const queryParams = new URLSearchParams(window.location.search); const handleLogin = async (e: FormEvent) => { e.preventDefault() try { if (!email || !password) { return; } setIsLoading(true); if (queryParams && queryParams.get("callback_port")) { const callbackPort = queryParams.get("callback_port") // attemptCliLogin const isCliLoginSuccessful = await attemptCliLogin({ email, password, }) if (isCliLoginSuccessful && isCliLoginSuccessful.success) { if (isCliLoginSuccessful.mfaEnabled) { // case: login requires MFA step setStep(1); setIsLoading(false); return; } // case: login was successful const cliUrl = `http://localhost:${callbackPort}` // send request to server endpoint const instance = axios.create() await instance.post(cliUrl, { ...isCliLoginSuccessful.loginResponse }) // cli page router.push("/cli-redirect"); // on success, router.push to cli Login Successful page } } else { const isLoginSuccessful = await attemptLogin({ email, password, }); if (isLoginSuccessful && isLoginSuccessful.success) { // case: login was successful if (isLoginSuccessful.mfaEnabled) { // case: login requires MFA step setStep(1); setIsLoading(false); return; } const userOrgs = await fetchOrganizations(); const userOrg = userOrgs[0] && userOrgs[0]._id; // case: login does not require MFA step createNotification({ text: "Successfully logged in", type: "success" }); router.push(`/org/${userOrg}/overview`); } } } catch (err) { setLoginError(true); createNotification({ text: "Login unsuccessful. Double-check your credentials and try again.", type: "error" }); } setIsLoading(false); } return (

Login to Infisical

or
setEmail(e.target.value)} type="email" placeholder="Enter your email..." isRequired autoComplete="username" className="h-11" />
setPassword(e.target.value)} type="password" placeholder="Enter your password..." isRequired autoComplete="current-password" id="current-password" className="h-11 select:-webkit-autofill:focus" />
{!isLoading && loginError && } { !serverDetails?.inviteOnlySignup ?
Don't have an acount yet? {t("login.create-account")}
:
}
Forgot password? Recover your account
); }