diff options
author | Sebastian <sebasjm@gmail.com> | 2023-03-15 07:21:26 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-03-15 07:22:03 -0300 |
commit | 41339c1db25306d8135084d24b1452a3ddd75dbb (patch) | |
tree | 930421098405de341162ff70bd390e666869c934 /packages/merchant-backoffice-ui/src/hooks | |
parent | 64c3cbc1dbc94c207bece0b9f6a399cdacd8dc22 (diff) | |
download | wallet-core-41339c1db25306d8135084d24b1452a3ddd75dbb.tar.xz |
check credetials on login
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/backend.ts | 19 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/index.ts | 3 |
2 files changed, 19 insertions, 3 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts b/packages/merchant-backoffice-ui/src/hooks/backend.ts index 6c4e5c176..93e95934e 100644 --- a/packages/merchant-backoffice-ui/src/hooks/backend.ts +++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts @@ -139,6 +139,25 @@ interface useBackendBaseRequestType { type YesOrNo = "yes" | "no"; +export function useCredentialsChecker() { + const { request } = useApiContext(); + //check against instance details endpoint + //while merchant backend doesn't have a login endpoint + return async function testLogin( + instance: string, + token: string, + ): Promise<boolean> { + try { + const response = await request(instance, `/private/`, { + token, + }); + return true; + } catch (e) { + return false; + } + }; +} + /** * * @param root the request is intended to the base URL and no the instance URL diff --git a/packages/merchant-backoffice-ui/src/hooks/index.ts b/packages/merchant-backoffice-ui/src/hooks/index.ts index bb210c9ba..316620cf7 100644 --- a/packages/merchant-backoffice-ui/src/hooks/index.ts +++ b/packages/merchant-backoffice-ui/src/hooks/index.ts @@ -59,7 +59,6 @@ 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(); @@ -74,8 +73,6 @@ export function useBackendInstanceToken( ): void { setToken((p) => { const toStore = value instanceof Function ? value(p) : value; - // setToken(value) - setRandom(new Date().getTime()); return toStore; }); } |