From 6ca936671e6d795b3e09dbb9b00d467b9f4c17ba Mon Sep 17 00:00:00 2001 From: Kato Date: Fri, 4 Sep 2026 16:45:00 +0000 Subject: [PATCH] Fix: save sessionid to localStorage as fallback for HttpOnly cookie --- js/main.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/js/main.js b/js/main.js index e841089..8b7bdc8 100644 --- a/js/main.js +++ b/js/main.js @@ -8,23 +8,32 @@ document.addEventListener('DOMContentLoaded', () => { function getCookie(name) { console.log('DEBUG getCookie: all cookies =', document.cookie); + + // Strategy 1: localStorage (for HttpOnly cookies) + const local = localStorage.getItem('sessionid'); + if (local) { + console.log('DEBUG getCookie:', name, '=', local, '(from localStorage)'); + return local; + } + + // Strategy 2: document.cookie (non-HttpOnly cookies) const raw = document.cookie; - // Strategy 1: semicolon prefix (cookies after first) + // Strategy 2a: semicolon prefix (cookies after first) const parts1 = raw.split(`; ${name}=`); if (parts1.length === 2) { const val = parts1.pop().split(';').shift(); const cleaned = val.replace(/^"|"$/g, ''); - console.log('DEBUG getCookie:', name, '=', cleaned); + console.log('DEBUG getCookie:', name, '=', cleaned, '(from cookie)'); return cleaned; } - // Strategy 2: no semicolon prefix (FIRST cookie in document.cookie) + // Strategy 2b: no semicolon prefix (FIRST cookie in document.cookie) const parts2 = raw.split(`${name}=`); if (parts2.length === 2) { const val = parts2.pop().split(';').shift(); const cleaned = val.replace(/^"|"$/g, ''); - console.log('DEBUG getCookie:', name, '=', cleaned, '(first cookie)'); + console.log('DEBUG getCookie:', name, '=', cleaned, '(from first cookie)'); return cleaned; } @@ -36,6 +45,8 @@ function setCookie(name, value, days) { const expires = new Date(); expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000); document.cookie = name + '=' + encodeURIComponent(value) + ';expires=' + expires.toUTCString() + ';path=/'; + // Also save to localStorage for HttpOnly cookies + localStorage.setItem(name, value); } const API_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/login';