31 lines
698 B
JavaScript
31 lines
698 B
JavaScript
import { getStorageKey } from "./config.js";
|
|
import { parseUserConsent, serializeUserConsent } from "./preferences.js";
|
|
|
|
export function readStoredConsent() {
|
|
if (typeof window === "undefined") return null;
|
|
|
|
try {
|
|
const raw = window.localStorage.getItem(getStorageKey());
|
|
if (!raw) return null;
|
|
|
|
try {
|
|
return parseUserConsent(JSON.parse(raw));
|
|
} catch {
|
|
return parseUserConsent(raw);
|
|
}
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function writeStoredConsent(consent) {
|
|
if (typeof window === "undefined") return false;
|
|
|
|
try {
|
|
window.localStorage.setItem(getStorageKey(), serializeUserConsent(consent));
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|