aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/components/exception/login.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/components/exception/login.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/components/exception/login.tsx22
1 files changed, 15 insertions, 7 deletions
diff --git a/packages/merchant-backoffice-ui/src/components/exception/login.tsx b/packages/merchant-backoffice-ui/src/components/exception/login.tsx
index 9a0411642..435ff1d6a 100644
--- a/packages/merchant-backoffice-ui/src/components/exception/login.tsx
+++ b/packages/merchant-backoffice-ui/src/components/exception/login.tsx
@@ -24,6 +24,7 @@ import { h, VNode } from "preact";
import { useState } from "preact/hooks";
import { useBackendContext } from "../../context/backend.js";
import { useInstanceContext } from "../../context/instance.js";
+import { useCredentialsChecker } from "../../hooks/backend.js";
import { Notification } from "../../utils/types.js";
interface Props {
@@ -31,15 +32,15 @@ interface Props {
onConfirm: (backend: string, token?: string) => void;
}
-function getTokenValuePart(t?: string): string | undefined {
+function getTokenValuePart(t: string): string {
if (!t) return t;
const match = /secret-token:(.*)/.exec(t);
- if (!match || !match[1]) return undefined;
+ if (!match || !match[1]) return "";
return match[1];
}
-function normalizeToken(r: string | undefined): string | undefined {
- return r ? `secret-token:${encodeURIComponent(r)}` : undefined;
+function normalizeToken(r: string): string {
+ return `secret-token:${encodeURIComponent(r)}`;
}
function cleanUp(s: string): string {
@@ -53,8 +54,9 @@ function cleanUp(s: string): string {
export function LoginModal({ onConfirm, withMessage }: Props): VNode {
const { url: backendUrl, token: baseToken } = useBackendContext();
const { admin, token: instanceToken } = useInstanceContext();
+ const testLogin = useCredentialsChecker();
const currentToken = getTokenValuePart(
- !admin ? baseToken : instanceToken || "",
+ (!admin ? baseToken : instanceToken) ?? "",
);
const [token, setToken] = useState(currentToken);
@@ -137,8 +139,14 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode {
>
<button
class="button is-info"
- onClick={(): void => {
- onConfirm(url, normalizeToken(token));
+ onClick={async () => {
+ const secretToken = normalizeToken(token);
+ const isOk = await testLogin(url, secretToken);
+ if (isOk) {
+ onConfirm(url, secretToken);
+ } else {
+ onConfirm(url);
+ }
}}
>
<i18n.Translate>Confirm</i18n.Translate>