diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/login/index.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/login/index.tsx | 119 |
1 files changed, 6 insertions, 113 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/login/index.tsx b/packages/merchant-backoffice-ui/src/paths/login/index.tsx index 30b5c37bd..272c40b55 100644 --- a/packages/merchant-backoffice-ui/src/paths/login/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/login/index.tsx @@ -19,10 +19,9 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { HttpStatusCode } from "@gnu-taler/taler-util"; +import { HttpStatusCode, createAccessToken } from "@gnu-taler/taler-util"; import { - useMerchantApiContext, - useTranslationContext, + useTranslationContext } from "@gnu-taler/web-util/browser"; import { ComponentChildren, Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; @@ -43,58 +42,19 @@ const tokenRequest = { export function LoginPage(_p: Props): VNode { const [token, setToken] = useState(""); const [notif, setNotif] = useState<Notification | undefined>(undefined); - const { state, logIn, impersonate } = useSessionContext(); - const { lib } = useMerchantApiContext(); + const { state, logIn } = useSessionContext(); + const { lib } = useSessionContext(); const { i18n } = useTranslationContext(); - async function doImpersonateImpl(instanceId: string) { - const newInstanceApi = lib.subInstanceApi(instanceId); - const cfg = await newInstanceApi.instance.getConfig(); - if (cfg.type !== "ok") { - setNotif({ - message: "Could not load the configuration of this instance.", - description: newInstanceApi.instance.baseUrl, - type: "ERROR", - }); - return; - } - const result = await newInstanceApi.authenticate.createAccessTokenBearer( - token, - tokenRequest, - ); - - if (result.type === "ok") { - const { token } = result.body; - impersonate({ instance: instanceId, baseUrl: new URL(newInstanceApi.instance.baseUrl), token }); - return; - } else { - switch (result.case) { - case HttpStatusCode.Unauthorized: { - setNotif({ - message: "Your password is incorrect", - type: "ERROR", - }); - return; - } - case HttpStatusCode.NotFound: { - setNotif({ - message: "Your instance not found", - type: "ERROR", - }); - return; - } - } - } - } async function doLoginImpl() { const result = await lib.authenticate.createAccessTokenBearer( - token, + createAccessToken(token), tokenRequest, ); if (result.type === "ok") { const { token } = result.body; - logIn({ token }); + logIn(token); return; } else { switch (result.case) { @@ -116,73 +76,6 @@ export function LoginPage(_p: Props): VNode { } } - if (state.status === "loggedIn" && state.impersonate !== undefined) { - //the user is loggedin but trying to do an impersonation - return ( - <div class="columns is-centered" style={{ margin: "auto" }}> - <div class="column is-two-thirds "> - <div class="modal-card" style={{ width: "100%", margin: 0 }}> - <header - class="modal-card-head" - style={{ border: "1px solid", borderBottom: 0 }} - > - <p class="modal-card-title">{i18n.str`Login required`}</p> - </header> - <section - class="modal-card-body" - style={{ border: "1px solid", borderTop: 0, borderBottom: 0 }} - > - <p> - <i18n.Translate> - Need the access token for the instance{" "} - <b>"{state.instance}"</b> - </i18n.Translate> - </p> - <div class="field is-horizontal"> - <div class="field-label is-normal"> - <label class="label"> - <i18n.Translate>Access Token</i18n.Translate> - </label> - </div> - <div class="field-body"> - <div class="field"> - <p class="control is-expanded"> - <input - class="input" - type="password" - placeholder={"current access token"} - name="token" - onKeyPress={(e) => - e.keyCode === 13 - ? doImpersonateImpl(state.instance) - : null - } - value={token} - onInput={(e): void => setToken(e?.currentTarget.value)} - /> - </p> - </div> - </div> - </div> - </section> - <footer - class="modal-card-foot " - style={{ - justifyContent: "flex-end", - border: "1px solid", - borderTop: 0, - }} - > - <AsyncButton onClick={() => doImpersonateImpl(state.instance)}> - <i18n.Translate>Confirm</i18n.Translate> - </AsyncButton> - </footer> - </div> - </div> - </div> - ); - } - return ( <Fragment> <NotificationCard notification={notif} /> |