summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/login/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/login/index.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/login/index.tsx116
1 files changed, 10 insertions, 106 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/login/index.tsx b/packages/merchant-backoffice-ui/src/paths/login/index.tsx
index 6a698186a..d77bc75fd 100644
--- a/packages/merchant-backoffice-ui/src/paths/login/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/login/index.tsx
@@ -19,22 +19,17 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
+import { HttpStatusCode, createRFC8959AccessTokenEncoded } from "@gnu-taler/taler-util";
import {
- HttpStatusCode
-} 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";
import { NotificationCard } from "../../components/menu/index.js";
-import {
- useSessionContext
-} from "../../context/session.js";
+import { useSessionContext } from "../../context/session.js";
import { Notification } from "../../utils/types.js";
-interface Props { }
+interface Props {}
const tokenRequest = {
scope: "write",
@@ -48,45 +43,18 @@ export function LoginPage(_p: Props): VNode {
const [token, setToken] = useState("");
const [notif, setNotif] = useState<Notification | undefined>(undefined);
const { state, logIn } = useSessionContext();
- const { lib } = useMerchantApiContext();
+ const { lib } = useSessionContext();
const { i18n } = useTranslationContext();
- async function doImpersonateImpl(instanceId: string) {
- const result = await lib
- .impersonate(instanceId)
- .createAccessTokenBearer(token, tokenRequest);
- if (result.type === "ok") {
- const { token } = result.body;
- logIn({ 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,
+ createRFC8959AccessTokenEncoded(token),
tokenRequest,
);
if (result.type === "ok") {
const { token } = result.body;
- logIn({ token });
+ logIn(token);
return;
} else {
switch (result.case) {
@@ -108,72 +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.
- </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} />
@@ -190,7 +92,9 @@ export function LoginPage(_p: Props): VNode {
class="modal-card-body"
style={{ border: "1px solid", borderTop: 0, borderBottom: 0 }}
>
- <i18n.Translate>Please enter your access token.</i18n.Translate>
+ <i18n.Translate>
+ Please enter your access token for <b>"{state.instance}"</b>.
+ </i18n.Translate>
<div class="field is-horizontal">
<div class="field-label is-normal">