taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 868820cdbfef59b711a7363974d7272946dae208
parent 916220c53a8be287ffacad3251ddebff33bbe4f2
Author: Florian Dold <florian@dold.me>
Date:   Sun,  6 Apr 2025 12:10:46 +0200

kyc-ui: Fix access token logic

Also add logging

Diffstat:
Mpackages/kyc-ui/src/hooks/session.ts | 29++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/packages/kyc-ui/src/hooks/session.ts b/packages/kyc-ui/src/hooks/session.ts @@ -21,7 +21,6 @@ import { codecForAccessToken, codecForList, codecForString, - codecOptional, codecOptionalDefault, } from "@gnu-taler/taler-util"; import { buildStorageKey, useLocalStorage } from "@gnu-taler/web-util/browser"; @@ -71,19 +70,23 @@ export function useSessionState(): SessionStateHandler { const [pref] = usePreferences(); const urlToken = getAccessTokenFromURL(); - // if the user access the SPA with a token in the URL then - // don't use the session saved in the storage - // unless we are on debugMode. Using debug mode will not - // use the URL token in order to switch session easily + // Normally, if the user accesses the SPA with an access token in the URL then + // switch to that access token. + // If we're in debug mode, preserve the access token. + let accessToken: AccessToken | undefined; + if (pref.showDebugInfo && state) { + console.log(`Preserving token, as debug mode is enabled`); + accessToken = state.accessToken; + } else { + accessToken = urlToken ?? state?.accessToken; + } return { - state: !state - ? undefined - : { - accessToken: pref.showDebugInfo - ? state.accessToken - : urlToken ?? state.accessToken, - testAccounts: state.testAccounts, - }, + state: accessToken + ? { + accessToken, + testAccounts: state?.testAccounts ?? [], + } + : undefined, start(accessToken) { update({ accessToken, testAccounts: [] }); },