aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/hooks')
-rw-r--r--packages/demobank-ui/src/hooks/backend.ts28
-rw-r--r--packages/demobank-ui/src/hooks/circuit.ts3
2 files changed, 30 insertions, 1 deletions
diff --git a/packages/demobank-ui/src/hooks/backend.ts b/packages/demobank-ui/src/hooks/backend.ts
index 3eaf1f186..851a3fb5b 100644
--- a/packages/demobank-ui/src/hooks/backend.ts
+++ b/packages/demobank-ui/src/hooks/backend.ts
@@ -16,6 +16,7 @@
import { canonicalizeBaseUrl } from "@gnu-taler/taler-util";
import {
+ ErrorType,
RequestError,
useLocalStorage,
} from "@gnu-taler/web-util/lib/index.browser";
@@ -192,6 +193,33 @@ export function usePublicBackend(): useBackendType {
};
}
+export function useCredentialsChecker() {
+ const { request } = useApiContext();
+ const baseUrl = getInitialBackendBaseURL();
+ //check against account details endpoint
+ //while sandbox backend doesn't have a login endpoint
+ return async function testLogin(
+ username: string,
+ password: string,
+ ): Promise<{
+ valid: boolean;
+ cause?: ErrorType;
+ }> {
+ try {
+ await request(baseUrl, `access-api/accounts/${username}/`, {
+ basicAuth: { username, password },
+ preventCache: true,
+ });
+ return { valid: true };
+ } catch (error) {
+ if (error instanceof RequestError) {
+ return { valid: false, cause: error.cause.type };
+ }
+ return { valid: false, cause: ErrorType.UNEXPECTED };
+ }
+ };
+}
+
export function useAuthenticatedBackend(): useBackendType {
const { state } = useBackendContext();
const { request: requestHandler } = useApiContext();
diff --git a/packages/demobank-ui/src/hooks/circuit.ts b/packages/demobank-ui/src/hooks/circuit.ts
index 548862d85..137a7aee2 100644
--- a/packages/demobank-ui/src/hooks/circuit.ts
+++ b/packages/demobank-ui/src/hooks/circuit.ts
@@ -288,9 +288,10 @@ export function useRatiosAndFeeConfig(): HttpResponse<
HttpResponseOk<SandboxBackend.Circuit.Config>,
RequestError<SandboxBackend.SandboxError>
>([`circuit-api/config`], fetcher, {
- refreshInterval: 1000,
+ refreshInterval: 60 * 1000,
refreshWhenHidden: false,
revalidateOnFocus: false,
+ revalidateIfStale: false,
revalidateOnReconnect: false,
refreshWhenOffline: false,
errorRetryCount: 0,