diff options
author | Sebastian <sebasjm@gmail.com> | 2023-08-04 13:32:08 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-08-07 08:14:43 -0300 |
commit | 37d0f9438e6e6507c46d56324e38a5f0c391ab45 (patch) | |
tree | 7cf2dfa017e5130ebc07e4692a897cb74a840df8 /packages/merchant-backoffice-ui/src/hooks/index.ts | |
parent | 44aeaba7b4d21e518928ca545b114e2a8e8c2a24 (diff) |
accesstoken in memory and better login when switching between accounts
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/index.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/index.ts | 25 |
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]; } |