Fix: save sessionid to localStorage as fallback for HttpOnly cookie
This commit is contained in:
+15
-4
@@ -8,23 +8,32 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
console.log('DEBUG getCookie: all cookies =', document.cookie);
|
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;
|
const raw = document.cookie;
|
||||||
|
|
||||||
// Strategy 1: semicolon prefix (cookies after first)
|
// Strategy 2a: semicolon prefix (cookies after first)
|
||||||
const parts1 = raw.split(`; ${name}=`);
|
const parts1 = raw.split(`; ${name}=`);
|
||||||
if (parts1.length === 2) {
|
if (parts1.length === 2) {
|
||||||
const val = parts1.pop().split(';').shift();
|
const val = parts1.pop().split(';').shift();
|
||||||
const cleaned = val.replace(/^"|"$/g, '');
|
const cleaned = val.replace(/^"|"$/g, '');
|
||||||
console.log('DEBUG getCookie:', name, '=', cleaned);
|
console.log('DEBUG getCookie:', name, '=', cleaned, '(from cookie)');
|
||||||
return cleaned;
|
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}=`);
|
const parts2 = raw.split(`${name}=`);
|
||||||
if (parts2.length === 2) {
|
if (parts2.length === 2) {
|
||||||
const val = parts2.pop().split(';').shift();
|
const val = parts2.pop().split(';').shift();
|
||||||
const cleaned = val.replace(/^"|"$/g, '');
|
const cleaned = val.replace(/^"|"$/g, '');
|
||||||
console.log('DEBUG getCookie:', name, '=', cleaned, '(first cookie)');
|
console.log('DEBUG getCookie:', name, '=', cleaned, '(from first cookie)');
|
||||||
return cleaned;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +45,8 @@ function setCookie(name, value, days) {
|
|||||||
const expires = new Date();
|
const expires = new Date();
|
||||||
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
||||||
document.cookie = name + '=' + encodeURIComponent(value) + ';expires=' + expires.toUTCString() + ';path=/';
|
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';
|
const API_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/login';
|
||||||
|
|||||||
Reference in New Issue
Block a user