fix: persist user_id/session_id in localStorage to prevent new session on reload
This commit is contained in:
parent
5943ad452d
commit
bd7ae3b565
1 changed files with 14 additions and 1 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue