diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/index.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/index.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/index.ts b/packages/merchant-backoffice-ui/src/hooks/index.ts index 0581d9938..bb210c9ba 100644 --- a/packages/merchant-backoffice-ui/src/hooks/index.ts +++ b/packages/merchant-backoffice-ui/src/hooks/index.ts @@ -59,6 +59,7 @@ export function useBackendDefaultToken( export function useBackendInstanceToken( id: string, ): [string | undefined, StateUpdater<string | undefined>] { + const [random, setRandom] = useState(0); const [token, setToken] = useLocalStorage(`backend-token-${id}`); const [defaultToken, defaultSetToken] = useBackendDefaultToken(); @@ -66,8 +67,20 @@ export function useBackendInstanceToken( if (id === "default") { return [defaultToken, defaultSetToken]; } + function updateToken( + value: + | (string | undefined) + | ((s: string | undefined) => string | undefined), + ): void { + setToken((p) => { + const toStore = value instanceof Function ? value(p) : value; + // setToken(value) + setRandom(new Date().getTime()); + return toStore; + }); + } - return [token, setToken]; + return [token, updateToken]; } export function useLang(initial?: string): [string, StateUpdater<string>] { |