Merge branch 'develop' into 'main'
AW-483-484-485-fix-bugs See merge request witapp/aura-webapp!807
This commit is contained in:
commit
f34c0cc64f
@ -25,6 +25,7 @@ export interface PayloadUpdate {
|
||||
profile?: Partial<ICreateAuthorizeUser>;
|
||||
partner?: Partial<Exclude<ICreateAuthorizeUser, "relationship_status">>;
|
||||
answers?: Partial<IAnswersSessionPalmistry | IAnswersSessionChats | IAnswersSessionCompatibilityV2 | IAnswersSessionCompatibilityV3 | IAnswersSessionCompatibilityV4>;
|
||||
cookies?: Record<string, string>; // Куки браузера
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<string | null>(null);
|
||||
const [token, setToken] = useState<string | null>(null);
|
||||
@ -75,6 +77,17 @@ export const useAuthentication = () => {
|
||||
return _date;
|
||||
}, [])
|
||||
|
||||
// Функция для получения всех куки браузера
|
||||
const getAllCookies = useCallback(() => {
|
||||
const cookies: Record<string, string> = {};
|
||||
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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user