Skip to content

Commit

Permalink
Allow forcing of new session (#2137)
Browse files Browse the repository at this point in the history
This PR adds two tweaks:

1) A query param to force Zupass to initialize a new session, only for
use with the Z API embedded use-case on shared devices (Frog Zone)

2) Cover a race condition for the "faster session creation" for Z API,
which meant that sometimes the slower path was being taken
  • Loading branch information
robknight authored Nov 10, 2024
1 parent 5ddeac7 commit 3b6266c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/passport-client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ import { ListenMode, useZappServer } from "../src/zapp/useZappServer";

enableLiveReload();

// Delete local storage and reload if forceNewSession is set
if (typeof window !== "undefined") {
const params = new URLSearchParams(window.location.search);
if (params.has("forceNewSession")) {
localStorage.clear();
const newParams = new URLSearchParams(window.location.search);
newParams.delete("forceNewSession");
const newSearch = newParams.toString();
const newPath = `${window.location.pathname}${
newSearch ? `?${newSearch}` : ""
}${window.location.hash}`;
window.location.replace(newPath);
}
}

function App(): JSX.Element {
useBackgroundJobs();
useZappServer(ListenMode.LISTEN_IF_EMBEDDED);
Expand Down
7 changes: 7 additions & 0 deletions apps/passport-client/src/zapp/useZappServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ async function waitForFirstSync(context: StateContextValue): Promise<void> {
return;
}
const unlisten = context.stateEmitter.listen((state) => {
if (
context.getState().downloadedPCDs &&
context.getState().pcds.getAllPCDsInFolder("Devcon SEA").length > 0
) {
resolve();
return;
}
if (state.completedFirstSync) {
unlisten();
resolve();
Expand Down

0 comments on commit 3b6266c

Please sign in to comment.