all repos — snow-editor @ 65993a713586363acceab129af67161a5fbe71cc

small and cozy markdown, and orgmode editor

src/lib/clientId.js (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
const STORAGE_CLIENT_ID = 'snow_client_id';

export function getOrCreateClientId() {
  try {
    const existing = localStorage.getItem(STORAGE_CLIENT_ID);
    if (existing) return existing;
  } catch {
    /* ignore */
  }

  const id = crypto.randomUUID();
  try {
    localStorage.setItem(STORAGE_CLIENT_ID, id);
  } catch {
    /* ignore */
  }
  return id;
}