AW-483-484-485-fix-bugs
This commit is contained in:
parent
aeaf62aef6
commit
357faa7a95
@ -25,6 +25,7 @@ export interface PayloadUpdate {
|
|||||||
profile?: Partial<ICreateAuthorizeUser>;
|
profile?: Partial<ICreateAuthorizeUser>;
|
||||||
partner?: Partial<Exclude<ICreateAuthorizeUser, "relationship_status">>;
|
partner?: Partial<Exclude<ICreateAuthorizeUser, "relationship_status">>;
|
||||||
answers?: Partial<IAnswersSessionPalmistry | IAnswersSessionChats | IAnswersSessionCompatibilityV2 | IAnswersSessionCompatibilityV3 | IAnswersSessionCompatibilityV4>;
|
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 { useTranslations } from "@/hooks/translations";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { Response } from "@/api/resources/Login";
|
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 feature = useSelector(selectors.selectFeature)
|
||||||
const { i18n } = useTranslations();
|
const { i18n } = useTranslations();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const { updateSession } = useSession();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [token, setToken] = useState<string | null>(null);
|
const [token, setToken] = useState<string | null>(null);
|
||||||
@ -75,6 +77,17 @@ export const useAuthentication = () => {
|
|||||||
return _date;
|
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 getAuthorizationPayload = useCallback((email: string, source: ESourceAuthorization): ICreateAuthorizePayload => {
|
||||||
const timezone = getClientTimezone();
|
const timezone = getClientTimezone();
|
||||||
@ -167,6 +180,17 @@ export const useAuthentication = () => {
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setError(null)
|
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 payload = getAuthorizationPayload(email, source);
|
||||||
const { token, userId: userIdFromApi, generatingVideo, videoId, authCode } = isAnonymous ? await api.authorizationAnonymous(payload) : await api.authorization(payload);
|
const { token, userId: userIdFromApi, generatingVideo, videoId, authCode } = isAnonymous ? await api.authorizationAnonymous(payload) : await api.authorization(payload);
|
||||||
if (!!token && !isAnonymous) {
|
if (!!token && !isAnonymous) {
|
||||||
@ -198,7 +222,7 @@ export const useAuthentication = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [api, dispatch, getAuthorizationPayload, signUp])
|
}, [api, dispatch, getAllCookies, getAuthorizationPayload, signUp, updateSession])
|
||||||
|
|
||||||
const anonymousAuthorization = useCallback(async ({
|
const anonymousAuthorization = useCallback(async ({
|
||||||
token,
|
token,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user