import { FormEvent, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import Link from "next/link"; import { useRouter } from "next/router"; import { faGithub, faGitlab, faGoogle } from "@fortawesome/free-brands-svg-icons"; import { faLock } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import Error from "@app/components/basic/Error"; import { createNotification } from "@app/components/notifications"; import attemptCliLogin from "@app/components/utilities/attemptCliLogin"; import attemptLogin from "@app/components/utilities/attemptLogin"; import { Button, Input } from "@app/components/v2"; import { useServerConfig } from "@app/context"; import { navigateUserToSelectOrg } from "../../Login.utils"; 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 { t } = useTranslation(); const [isLoading, setIsLoading] = useState(false); const [loginError, setLoginError] = useState(false); const { config } = useServerConfig(); const queryParams = new URLSearchParams(window.location.search); useEffect(() => { if ( process.env.NEXT_PUBLIC_SAML_ORG_SLUG && process.env.NEXT_PUBLIC_SAML_ORG_SLUG !== "saml-org-slug-default" ) { const callbackPort = queryParams.get("callback_port"); window.open( `/api/v1/sso/redirect/saml2/organizations/${process.env.NEXT_PUBLIC_SAML_ORG_SLUG}${ callbackPort ? `?callback_port=${callbackPort}` : "" }` ); window.close(); } }, []); 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: email.toLowerCase(), password }); if (isCliLoginSuccessful && isCliLoginSuccessful.success) { if (isCliLoginSuccessful.mfaEnabled) { // case: login requires MFA step setStep(1); setIsLoading(false); return; } navigateUserToSelectOrg(router, callbackPort!); } else { setLoginError(true); createNotification({ text: "CLI login unsuccessful. Double-check your credentials and try again.", type: "error" }); } } else { const isLoginSuccessful = await attemptLogin({ email: email.toLowerCase(), password }); if (isLoginSuccessful && isLoginSuccessful.success) { // case: login was successful if (isLoginSuccessful.mfaEnabled) { // case: login requires MFA step setStep(1); setIsLoading(false); return; } navigateUserToSelectOrg(router); // case: login does not require MFA step createNotification({ text: "Successfully logged in", type: "success" }); } } } catch (err) { console.error(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-10" />
setPassword(e.target.value)} type="password" placeholder="Enter your password..." isRequired autoComplete="current-password" id="current-password" className="select:-webkit-autofill:focus h-10" />
{!isLoading && loginError && } {config.allowSignUp ? (
Don't have an account yet? {t("login.create-account")}
) : (
)}
Forgot password? Recover your account
); };