From 665741255c44fadef8fcd5cab8ffbb3685a146ac Mon Sep 17 00:00:00 2001 From: Ali Raza <87068339+aliraza556@users.noreply.github.com> Date: Thu, 26 Dec 2024 20:34:46 +0500 Subject: [PATCH] feat: implement browser session ID tracking (#813) --- src/store/index.tsx | 1 + src/store/main.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/store/index.tsx b/src/store/index.tsx index fb49732d..d9e89bf8 100644 --- a/src/store/index.tsx +++ b/src/store/index.tsx @@ -16,6 +16,7 @@ import { chatHistoryStore } from './chat'; function hydrateAll() { Promise.all([hydrate('main', mainStore), hydrate('ui', uiStore)]).then(() => { + mainStore.initializeSessionId(); uiStore.setReady(true); }); } diff --git a/src/store/main.ts b/src/store/main.ts index f7f6b9d1..f73884da 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -2093,6 +2093,25 @@ export class MainStore { } } + @observable + sessionId = ''; + + @action setSessionId(id: string) { + this.sessionId = id; + } + + initializeSessionId() { + let sessionId = sessionStorage.getItem('sphinx_session_id'); + + if (!sessionId) { + sessionId = randomString(32); + sessionStorage.setItem('sphinx_session_id', sessionId); + } + + this.setSessionId(sessionId); + return sessionId; + } + @persist('object') @observable keysendInvoice = '';