diff --git a/apps/web/modules/auth/login-view.tsx b/apps/web/modules/auth/login-view.tsx index 52d675f4fa..4dc923e9a7 100644 --- a/apps/web/modules/auth/login-view.tsx +++ b/apps/web/modules/auth/login-view.tsx @@ -11,8 +11,15 @@ import { z } from "zod"; import { SAMLLogin } from "@calcom/web/modules/auth/components/SAMLLogin"; import { ErrorCode } from "@calcom/features/auth/lib/ErrorCode"; -import { LastUsed, useLastUsed } from "@calcom/web/modules/auth/hooks/useLastUsed"; -import { HOSTED_CAL_FEATURES, WEBAPP_URL, WEBSITE_URL } from "@calcom/lib/constants"; +import { + LastUsed, + useLastUsed, +} from "@calcom/web/modules/auth/hooks/useLastUsed"; +import { + HOSTED_CAL_FEATURES, + WEBAPP_URL, + WEBSITE_URL, +} from "@calcom/lib/constants"; import { emailRegex } from "@calcom/lib/emailSchema"; import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl"; import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams"; @@ -40,7 +47,11 @@ interface LoginValues { } const GoogleIcon = () => ( - + ); export type PageProps = inferSSRProps; export default function Login({ @@ -60,13 +71,17 @@ export default function Login({ .string() .min(1, `${t("error_required_field")}`) .regex(emailRegex, `${t("enter_valid_email")}`), - ...(totpEmail ? {} : { password: z.string().min(1, `${t("error_required_field")}`) }), + ...(totpEmail + ? {} + : { password: z.string().min(1, `${t("error_required_field")}`) }), }) // Passthrough other fields like totpCode .passthrough(); const methods = useForm({ resolver: zodResolver(formSchema) }); const { register, formState } = methods; - const [twoFactorRequired, setTwoFactorRequired] = useState(!!totpEmail || false); + const [twoFactorRequired, setTwoFactorRequired] = useState( + !!totpEmail || false + ); const [twoFactorLostAccess, setTwoFactorLostAccess] = useState(false); const [errorMessage, setErrorMessage] = useState(null); const [lastUsed, setLastUsed] = useLastUsed(); @@ -75,9 +90,15 @@ export default function Login({ // [ErrorCode.SecondFactorRequired]: t("2fa_enabled_instructions"), // Don't leak information about whether an email is registered or not [ErrorCode.IncorrectEmailPassword]: t("incorrect_email_password"), - [ErrorCode.IncorrectTwoFactorCode]: `${t("incorrect_2fa_code")} ${t("please_try_again")}`, - [ErrorCode.InternalServerError]: `${t("something_went_wrong")} ${t("please_try_again_and_contact_us")}`, - [ErrorCode.ThirdPartyIdentityProviderEnabled]: t("account_created_with_identity_provider"), + [ErrorCode.IncorrectTwoFactorCode]: `${t("incorrect_2fa_code")} ${t( + "please_try_again" + )}`, + [ErrorCode.InternalServerError]: `${t("something_went_wrong")} ${t( + "please_try_again_and_contact_us" + )}`, + [ErrorCode.ThirdPartyIdentityProviderEnabled]: t( + "account_created_with_identity_provider" + ), }; let callbackUrl = searchParams?.get("callbackUrl") || ""; @@ -93,8 +114,12 @@ export default function Login({ callbackUrl = safeCallbackUrl || ""; + const signupUrl = callbackUrl + ? `${WEBSITE_URL}/signup?redirect=${encodeURIComponent(callbackUrl)}` + : `${WEBSITE_URL}/signup`; + const LoginFooter = ( - + {t("dont_have_an_account")} ); @@ -113,7 +138,8 @@ export default function Login({ setErrorMessage(null); }} StartIcon="arrow-left" - color="minimal"> + color="minimal" + > {t("go_back")} {!twoFactorLostAccess ? ( @@ -124,7 +150,8 @@ export default function Login({ methods.setValue("totpCode", ""); }} StartIcon="lock" - color="minimal"> + color="minimal" + > {t("lost_access")} ) : null} @@ -136,7 +163,8 @@ export default function Login({ onClick={() => { window.location.replace("/"); }} - color="minimal"> + color="minimal" + > {t("cancel")} ); @@ -154,14 +182,18 @@ export default function Login({ else if (!res.error) { setLastUsed("credentials"); router.push(callbackUrl); - } else if (res.error === ErrorCode.SecondFactorRequired) setTwoFactorRequired(true); - else if (res.error === ErrorCode.IncorrectBackupCode) setErrorMessage(t("incorrect_backup_code")); - else if (res.error === ErrorCode.MissingBackupCodes) setErrorMessage(t("missing_backup_codes")); + } else if (res.error === ErrorCode.SecondFactorRequired) + setTwoFactorRequired(true); + else if (res.error === ErrorCode.IncorrectBackupCode) + setErrorMessage(t("incorrect_backup_code")); + else if (res.error === ErrorCode.MissingBackupCodes) + setErrorMessage(t("missing_backup_codes")); // fallback if error not found else setErrorMessage(errorMessages[res.error] || t("something_went_wrong")); }; - const { data, isPending, error } = trpc.viewer.public.ssoConnections.useQuery(); + const { data, isPending, error } = + trpc.viewer.public.ssoConnections.useQuery(); useEffect( function refactorMeWithoutEffect() { @@ -186,10 +218,12 @@ export default function Login({ ? !totpEmail ? TwoFactorFooter : ExternalTotpFooter - : process.env.NEXT_PUBLIC_DISABLE_SIGNUP !== "true" && searchParams?.get("register") !== "false" + : process.env.NEXT_PUBLIC_DISABLE_SIGNUP !== "true" && + searchParams?.get("register") !== "false" ? LoginFooter : null - }> + } + > {!twoFactorRequired && ( <> @@ -197,7 +231,7 @@ export default function Login({ {isGoogleLoginEnabled && ( } @@ -207,7 +241,8 @@ export default function Login({ await signIn("google", { callbackUrl, }); - }}> + }} + > {t("signin_with_google")} {lastUsed === "google" && } @@ -223,28 +258,43 @@ export default function Login({ {(isGoogleLoginEnabled || displaySSOLogin) && ( - - - + + + {t("or").toLocaleLowerCase()} - + )} > )} - + - + - + + className="text-sm font-medium text-default" + > {t("forgot")} - {twoFactorRequired ? !twoFactorLostAccess ? : : null} + {twoFactorRequired ? ( + !twoFactorLostAccess ? ( + + ) : ( + + ) + ) : null} {errorMessage && } + className="justify-center w-full" + > {twoFactorRequired ? t("submit") : t("sign_in")} - {lastUsed === "credentials" && !twoFactorRequired && } + {lastUsed === "credentials" && !twoFactorRequired && ( + + )} diff --git a/apps/web/modules/onboarding/hooks/useSubmitPersonalOnboarding.ts b/apps/web/modules/onboarding/hooks/useSubmitPersonalOnboarding.ts index d6c79f02fe..2f33f46ee1 100644 --- a/apps/web/modules/onboarding/hooks/useSubmitPersonalOnboarding.ts +++ b/apps/web/modules/onboarding/hooks/useSubmitPersonalOnboarding.ts @@ -6,6 +6,7 @@ import { trpc } from "@calcom/trpc/react"; import { showToast } from "@calcom/ui/components/toast"; import { setShowWelcomeToCalcomModalFlag } from "@calcom/web/modules/shell/hooks/useWelcomeToCalcomModal"; +const ONBOARDING_REDIRECT_KEY = "onBoardingRedirect"; const ORG_MODAL_STORAGE_KEY = "showNewOrgModal"; const DEFAULT_EVENT_TYPES = [ @@ -56,6 +57,14 @@ export const useSubmitPersonalOnboarding = () => { } await utils.viewer.me.get.refetch(); + + const redirectUrl = localStorage.getItem(ONBOARDING_REDIRECT_KEY); + if (redirectUrl) { + localStorage.removeItem(ONBOARDING_REDIRECT_KEY); + router.push(redirectUrl); + return; + } + // Check if org modal flag is set - if so, don't show personal modal // Organization onboarding takes precedence const hasOrgModalFlag = sessionStorage.getItem(ORG_MODAL_STORAGE_KEY) === "true";