diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/index.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/index.ts | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/index.ts b/packages/merchant-backoffice-ui/src/hooks/index.ts index b77b9dea8..79b22304a 100644 --- a/packages/merchant-backoffice-ui/src/hooks/index.ts +++ b/packages/merchant-backoffice-ui/src/hooks/index.ts @@ -19,9 +19,10 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { StateUpdater, useCallback, useState } from "preact/hooks"; +import { StateUpdater, useCallback, useEffect, useState } from "preact/hooks"; import { ValueOrFunction } from "../utils/types.js"; import { useMemoryStorage } from "@gnu-taler/web-util/browser"; +import { useMatchMutate } from "./backend.js"; const calculateRootPath = () => { const rootPath = @@ -56,8 +57,22 @@ export function useBackendDefaultToken( ): [string | undefined, ((d: string | undefined) => void)] { // uncomment for testing initialValue = "secret-token:secret" as string | undefined - const { update, value } = useMemoryStorage(`backend-token`, initialValue) - return [value, update]; + const { update: setToken, value: token, reset } = useMemoryStorage(`backend-token`, initialValue) + const clearCache = useMatchMutate() + useEffect(() => { + clearCache() + }, [token]) + + function updateToken( + value: (string | undefined) + ): void { + if (value === undefined) { + reset() + } else { + setToken(value) + } + } + return [token, updateToken]; } export function useBackendInstanceToken( @@ -73,14 +88,12 @@ export function useBackendInstanceToken( function updateToken( value: (string | undefined) ): void { - console.log("seeting token", value) if (value === undefined) { reset() } else { setToken(value) } } - console.log("token", token) return [token, updateToken]; } |