fix: persist user_id/session_id in localStorage to prevent new session on reload

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-03-16 13:15:48 -03:00
parent 5943ad452d
commit bd7ae3b565

View file

@ -1444,7 +1444,14 @@
function proceedWithChatInit() { function proceedWithChatInit() {
var botName = window.__INITIAL_BOT_NAME__ || "default"; var botName = window.__INITIAL_BOT_NAME__ || "default";
fetch("/api/auth?bot_name=" + encodeURIComponent(botName)) var storageKey = "gb_chat_" + botName;
var stored = {};
try { stored = JSON.parse(localStorage.getItem(storageKey) || "{}"); } catch(e) {}
var authUrl = "/api/auth?bot_name=" + encodeURIComponent(botName);
if (stored.user_id) authUrl += "&user_id=" + encodeURIComponent(stored.user_id);
fetch(authUrl)
.then(function (response) { .then(function (response) {
return response.json(); return response.json();
}) })
@ -1453,6 +1460,12 @@
currentSessionId = auth.session_id; currentSessionId = auth.session_id;
currentBotId = auth.bot_id || "default"; currentBotId = auth.bot_id || "default";
currentBotName = botName; currentBotName = botName;
try {
localStorage.setItem(storageKey, JSON.stringify({
user_id: currentUserId,
session_id: currentSessionId
}));
} catch(e) {}
console.log("Auth:", { console.log("Auth:", {
currentUserId: currentUserId, currentUserId: currentUserId,
currentSessionId: currentSessionId, currentSessionId: currentSessionId,