summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/hooks/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/index.ts')
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/index.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/index.ts b/packages/merchant-backoffice-ui/src/hooks/index.ts
index 316620cf7..10e77716e 100644
--- a/packages/merchant-backoffice-ui/src/hooks/index.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/index.ts
@@ -21,6 +21,7 @@
import { StateUpdater, useCallback, useState } from "preact/hooks";
import { ValueOrFunction } from "../utils/types.js";
+import { useMemoryStorage } from "@gnu-taler/web-util/browser";
const calculateRootPath = () => {
const rootPath =
@@ -52,14 +53,15 @@ export function useBackendURL(
export function useBackendDefaultToken(
initialValue?: string,
-): [string | undefined, StateUpdater<string | undefined>] {
- return useLocalStorage("backend-token", initialValue);
+): [string | undefined, ((d:string | undefined) => void)] {
+ const {update, value} = useMemoryStorage(`backend-token`, initialValue)
+ return [value, update];
}
export function useBackendInstanceToken(
id: string,
-): [string | undefined, StateUpdater<string | undefined>] {
- const [token, setToken] = useLocalStorage(`backend-token-${id}`);
+): [string | undefined, ((d:string | undefined) => void)] {
+ const {update:setToken, value:token, reset} = useMemoryStorage(`backend-token-${id}`)
const [defaultToken, defaultSetToken] = useBackendDefaultToken();
// instance named 'default' use the default token
@@ -67,15 +69,16 @@ export function useBackendInstanceToken(
return [defaultToken, defaultSetToken];
}
function updateToken(
- value:
- | (string | undefined)
- | ((s: string | undefined) => string | undefined),
+ value: (string | undefined)
): void {
- setToken((p) => {
- const toStore = value instanceof Function ? value(p) : value;
- return toStore;
- });
+ console.log("seeting token", value)
+ if (value === undefined) {
+ reset()
+ } else {
+ setToken(value)
+ }
}
+ console.log("token", token)
return [token, updateToken];
}