From 357faa7a9526aadbb18660ccba53b3aa25908b7b Mon Sep 17 00:00:00 2001 From: Daniil Chemerkin Date: Wed, 30 Jul 2025 00:08:14 +0000 Subject: [PATCH] AW-483-484-485-fix-bugs --- src/api/resources/Session.ts | 1 + .../authentication/use-authentication.ts | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/api/resources/Session.ts b/src/api/resources/Session.ts index 9626a83..5707e8b 100644 --- a/src/api/resources/Session.ts +++ b/src/api/resources/Session.ts @@ -25,6 +25,7 @@ export interface PayloadUpdate { profile?: Partial; partner?: Partial>; answers?: Partial; + cookies?: Record; // Куки браузера } } diff --git a/src/hooks/authentication/use-authentication.ts b/src/hooks/authentication/use-authentication.ts index da4780c..6b98b49 100644 --- a/src/hooks/authentication/use-authentication.ts +++ b/src/hooks/authentication/use-authentication.ts @@ -11,6 +11,7 @@ import { useCallback, useMemo, useState } from "react"; import { useTranslations } from "@/hooks/translations"; import { useDispatch, useSelector } from "react-redux"; import { Response } from "@/api/resources/Login"; +import { useSession } from "@/hooks/session/useSession"; @@ -19,6 +20,7 @@ export const useAuthentication = () => { const feature = useSelector(selectors.selectFeature) const { i18n } = useTranslations(); const dispatch = useDispatch(); + const { updateSession } = useSession(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [token, setToken] = useState(null); @@ -75,6 +77,17 @@ export const useAuthentication = () => { return _date; }, []) + // Функция для получения всех куки браузера + const getAllCookies = useCallback(() => { + const cookies: Record = {}; + document.cookie.split(';').forEach(cookie => { + const [name, value] = cookie.trim().split('='); + if (name && value) { + cookies[name] = decodeURIComponent(value); + } + }); + return cookies; + }, []); const getAuthorizationPayload = useCallback((email: string, source: ESourceAuthorization): ICreateAuthorizePayload => { const timezone = getClientTimezone(); @@ -167,6 +180,17 @@ export const useAuthentication = () => { try { setIsLoading(true); setError(null) + + // Обновляем сессию с куки перед авторизацией + try { + const cookies = getAllCookies(); + await updateSession({ cookies }, source); + console.log('Session updated with cookies before authorization:', cookies); + } catch (sessionError) { + console.warn('Failed to update session with cookies:', sessionError); + // Продолжаем авторизацию даже если обновление сессии не удалось + } + const payload = getAuthorizationPayload(email, source); const { token, userId: userIdFromApi, generatingVideo, videoId, authCode } = isAnonymous ? await api.authorizationAnonymous(payload) : await api.authorization(payload); if (!!token && !isAnonymous) { @@ -198,7 +222,7 @@ export const useAuthentication = () => { } finally { setIsLoading(false); } - }, [api, dispatch, getAuthorizationPayload, signUp]) + }, [api, dispatch, getAllCookies, getAuthorizationPayload, signUp, updateSession]) const anonymousAuthorization = useCallback(async ({ token,