merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit bb786c93be9f5ff2a8f7d30bbaf14d6f4f4f5a1d
parent db35cb909f1771ecd724515b4e9395f68fa91f18
Author: Sebastian <sebasjm@gmail.com>
Date:   Mon, 31 May 2021 11:57:15 -0300

prevent login dialog to be updated with secret-token

Diffstat:
Mpackages/frontend/src/components/exception/login.tsx | 26++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/packages/frontend/src/components/exception/login.tsx b/packages/frontend/src/components/exception/login.tsx @@ -31,18 +31,20 @@ interface Props { onConfirm: (backend: string, token?: string) => void; } +function getTokenValuePart(t?: string): string | undefined { + if (!t) return t + const match = /secret-token:(.*)/.exec(t); + if (!match || !match[1]) return undefined; + return match[1] +} + + export function LoginModal({ onConfirm, withMessage }: Props): VNode { const { url: backendUrl, token: baseToken } = useBackendContext() const { admin, token: instanceToken } = useInstanceContext() - const [token, setToken] = useState(!admin ? baseToken : instanceToken || '') + const currentToken = getTokenValuePart(!admin ? baseToken : instanceToken || '') + const [token, setToken] = useState(currentToken) - function updateToken(token:string) { - const value = token && token.startsWith('secret-token:')? - token.substring('secret-token:'.length) : token - - setToken(`secret-token:${value}`) - } - const [url, setURL] = useState(backendUrl) const i18n = useTranslator() @@ -63,7 +65,7 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { <p class="control is-expanded"> <input class="input" type="text" placeholder="set new url" name="id" value={url} - onKeyPress={e => e.keyCode === 13 ? onConfirm(url, token ? token : undefined) : null} + onKeyPress={e => e.keyCode === 13 ? onConfirm(url, token ? `secret-token:${token}` : undefined) : null} onInput={(e): void => setURL(e?.currentTarget.value)} /> </p> @@ -78,9 +80,9 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { <div class="field"> <p class="control is-expanded"> <input class="input" type="text" placeholder={"set new token"} name="token" - onKeyPress={e => e.keyCode === 13 ? onConfirm(url, token ? token : undefined) : null} + onKeyPress={e => e.keyCode === 13 ? onConfirm(url, token ? `secret-token:${token}` : undefined) : null} value={token} - onInput={(e): void => updateToken(e?.currentTarget.value)} + onInput={(e): void => setToken(e?.currentTarget.value)} /> </p> </div> @@ -89,7 +91,7 @@ export function LoginModal({ onConfirm, withMessage }: Props): VNode { </section> <footer class="modal-card-foot " style={{ justifyContent: 'flex-end', border: '1px solid', borderTop: 0 }} > <button class="button is-info" onClick={(): void => { - onConfirm(url, token ? token : undefined); + onConfirm(url, token ? `secret-token:${token}` : undefined); }} ><Translate>Confirm</Translate></button> </footer> </div>