fix: improve legacy session key handling by trimming whitespace

This commit is contained in:
Usman Baig
2026-01-17 16:08:56 +01:00
parent 02062b6518
commit eafa66f450

View File

@@ -31,14 +31,15 @@
// * Use a static key for session storage to ensure consistency across pages // * Use a static key for session storage to ensure consistency across pages
const key = 'ciphera_session_id'; const key = 'ciphera_session_id';
// * Legacy key support for migration // * Legacy key support for migration (strip whitespace just in case)
const legacyKey = 'plausible_session_' + domain; const legacyKey = 'plausible_session_' + (domain ? domain.trim() : '');
try { try {
// * Try to get existing session ID
cachedSessionId = sessionStorage.getItem(key); cachedSessionId = sessionStorage.getItem(key);
// * If not found in new key, try legacy key and migrate // * If not found in new key, try legacy key and migrate
if (!cachedSessionId) { if (!cachedSessionId && legacyKey) {
cachedSessionId = sessionStorage.getItem(legacyKey); cachedSessionId = sessionStorage.getItem(legacyKey);
if (cachedSessionId) { if (cachedSessionId) {
sessionStorage.setItem(key, cachedSessionId); sessionStorage.setItem(key, cachedSessionId);