Skip to content

Commit

Permalink
feat: implement browser session ID tracking (stakwork#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 authored Dec 26, 2024
1 parent 5c2bd51 commit 6657412
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { chatHistoryStore } from './chat';

function hydrateAll() {
Promise.all([hydrate('main', mainStore), hydrate('ui', uiStore)]).then(() => {
mainStore.initializeSessionId();
uiStore.setReady(true);
});
}
Expand Down
19 changes: 19 additions & 0 deletions src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down

0 comments on commit 6657412

Please sign in to comment.