From 7a77e3f05923ce5d1b1a9b3618cd553b8b18afba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=9A=D0=B0=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Mon, 17 Jun 2024 21:34:17 +0000 Subject: [PATCH] AW-111-auth-bug --- .../v1/pages/EmailEnterPage/index.tsx | 47 +++++++++++++------ .../authentication/use-authentication.ts | 1 + 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/components/pages/ABDesign/v1/pages/EmailEnterPage/index.tsx b/src/components/pages/ABDesign/v1/pages/EmailEnterPage/index.tsx index 106c13b..fc7d962 100644 --- a/src/components/pages/ABDesign/v1/pages/EmailEnterPage/index.tsx +++ b/src/components/pages/ABDesign/v1/pages/EmailEnterPage/index.tsx @@ -40,7 +40,7 @@ function EmailEnterPage({ const [isAuth, setIsAuth] = useState(false); const { subPlan } = useParams(); const { width: pageWidth, elementRef: pageRef } = useDynamicSize({}); - const { error, isLoading, authorization } = useAuthentication(); + const { error, isLoading, token, user, authorization } = useAuthentication(); const { gender } = useSelector(selectors.selectQuestionnaire); const activeProductFromStore = useSelector(selectors.selectActiveProduct); const { products } = usePaywall({ @@ -106,17 +106,34 @@ function EmailEnterPage({ source = ESourceAuthorization["aura.moons"]; } await authorization(email, source); - dispatch( - actions.payment.update({ - activeProduct, - }) - ); - setIsAuth(true); - setTimeout(() => { - navigate(redirectUrl); - }, 1000); }; + useEffect(() => { + if (user && token?.length && !isLoading && !error) { + dispatch( + actions.payment.update({ + activeProduct, + }) + ); + setIsAuth(true); + const timeout = setTimeout(() => { + navigate(redirectUrl); + }, 1000); + return () => { + clearTimeout(timeout); + }; + } + }, [ + activeProduct, + dispatch, + error, + isLoading, + navigate, + redirectUrl, + token?.length, + user, + ]); + return (

{t("we_dont_share")}

setIsValidEmail(false)} + name="email" + value={email} + placeholder={t("your_email")} + onValid={handleValidEmail} + onInvalid={() => setIsValidEmail(false)} /> { const authorization = useCallback(async (email: string, source: ESourceAuthorization) => { try { setIsLoading(true); + setError(null) const payload = getAuthorizationPayload(email, source); const { token, userId } = await api.authorization(payload); const { user } = await api.getUser({ token });