37 lines
786 B
JavaScript
37 lines
786 B
JavaScript
// 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 re‑read 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;
|
||
}
|
||
|
||
|