fix: cookie retrieve

This commit is contained in:
moanos [he/him] 2025-04-17 00:11:33 +02:00
parent 560f578b26
commit 0eff71732e

View File

@ -7,12 +7,20 @@ import TelemetryDeck from '@telemetrydeck/sdk';
// Telemetry Deck only collects fully anonymized data! // Telemetry Deck only collects fully anonymized data!
const getCookieValueOrNull = (name) => {
const cookie = document.cookie
.split(";")
.map(c => c.trim())
.find(c => c.startsWith(name + "="));
return cookie ? cookie.split("=")[1] : null;
};
function getOrCreateUUID() { function getOrCreateUUID() {
let cookie = document.cookie.split(";").some((item) => item.trim().startsWith("id=")); let cookie_val = getCookieValueOrNull("id");
if ( if (
cookie cookie_val
) { ) {
return cookie.split("=")[1]; return cookie_val;
} else { } else {
let uuid =crypto.randomUUID(); let uuid =crypto.randomUUID();
const days = 365; const days = 365;