создание, правка, удаление, скрытие инструмента

This commit is contained in:
2025-12-12 23:50:38 +03:00
parent 8b38d69980
commit f85ca7d002
19 changed files with 1607 additions and 162 deletions
+17 -7
View File
@@ -23,16 +23,26 @@ export async function setCookie(name, value, days = 180) {
}
}
const secure = true; // TODO включить после тестов
const sameSite = 'Lax';
const expires = new Date(Date.now() + days * 864e5).toUTCString();
const encodedName = encodeURIComponent(name);
let cookie = `${encodeURIComponent(name)}=${cookieValue}; expires=${expires}; path=/`;
if (secure) cookie += '; Secure';
if (sameSite) cookie += `; SameSite=${sameSite}`;
// ---------- 1. Пытаемся установить безопасную куку ----------
let secureCookie = `${encodedName}=${cookieValue}; expires=${expires}; path=/; Secure; SameSite=Lax`;
document.cookie = secureCookie;
document.cookie = cookie;
// ---------- 2. Проверяем, записалась ли она ----------
const isSet = document.cookie.split('; ')
.some(c => c.startsWith(`${encodedName}=`));
if (isSet) {
return true; // безопасная кука успешно установлена
}
// ---------- 3. Фолбэк: ставим обычную (без Secure) ----------
let normalCookie = `${encodedName}=${cookieValue}; expires=${expires}; path=/; SameSite=Lax`;
document.cookie = normalCookie;
return false; // безопасную куку установить не удалось
}
export async function getCookie(name) {