Files
chat-proxy/frontend/src/useSessionId.js
T
2025-09-03 12:26:32 +00:00

37 lines
786 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// useSessionId.js
export function getUserId() {
let id = localStorage.getItem("userId");
if (!id) {
id = crypto.randomUUID();
localStorage.setItem("userId", id);
}
return id;
}
export function getSessionId() {
// Legge sempre da localStorage
return localStorage.getItem("sessionId") || null;
}
export function getSessionIdForced() {
// Always reread localStorage so latest value is returned
let id = localStorage.getItem("sessionId");
if (!id) {
id = crypto.randomUUID();
localStorage.setItem("sessionId", id);
}
return id;
}
export function setSessionId(id) {
localStorage.setItem("sessionId", id);
}
export function resetSessionId() {
const newId = crypto.randomUUID();
localStorage.setItem("sessionId", newId);
return newId;
}