File size: 760 Bytes
1643ce8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const SESSION_KEY = "repex_session_id";

export function getStoredSessionId(): string {
  return localStorage.getItem(SESSION_KEY) || "";
}

export function setStoredSessionId(id: string): void {
  if (!id) return;
  localStorage.setItem(SESSION_KEY, id);
}

export function clearStoredSessionId(): void {
  localStorage.removeItem(SESSION_KEY);
}

export function getSessionIdFromSearch(search: string): string {
  const params = new URLSearchParams(search);
  return params.get("session") || "";
}

export function getSessionId(search: string): string {
  return getSessionIdFromSearch(search) || getStoredSessionId();
}

export function buildSessionQuery(sessionId: string): string {
  return sessionId ? `?session=${encodeURIComponent(sessionId)}` : "";
}