diff --git a/tfweb/src/components/QrCode.svelte b/tfweb/src/components/QrCode.svelte index bb7149d..4db4f08 100644 --- a/tfweb/src/components/QrCode.svelte +++ b/tfweb/src/components/QrCode.svelte @@ -14,14 +14,7 @@ if (canvas === undefined) { logger.warn(`component has not yet mounted, delaying 500ms and trying again`); setTimeout(() => { - logger.info(`updating qrcode to ${value}`); - QRCode.toCanvas(canvas, value, (err) => { - if (err) { - logger.error(`error updating qrcode: ${err}`); - } else { - logger.info(`qrcode updated successfully`); - } - }) + updateQrCode(); }, 500); return; } diff --git a/tfweb/src/lib/i18n/locales/en.json b/tfweb/src/lib/i18n/locales/en.json index c1e6c62..29d97da 100644 --- a/tfweb/src/lib/i18n/locales/en.json +++ b/tfweb/src/lib/i18n/locales/en.json @@ -58,7 +58,8 @@ "button": "Enable 2FA", "error": { "generic": "Unable to enable 2fa: {err}", - "api": "Unable to contact the server. Try again later." + "api": "Unable to contact the server. Try again later.", + "ERR_UNAUTHORIZED": "Incorrect 2FA code" } }, "2fa": { diff --git a/tfweb/src/routes/2fasetup/+page.svelte b/tfweb/src/routes/2fasetup/+page.svelte index 4a33a28..47cf793 100644 --- a/tfweb/src/routes/2fasetup/+page.svelte +++ b/tfweb/src/routes/2fasetup/+page.svelte @@ -13,7 +13,7 @@ let loading = true; let isError = false; let error = ''; - $: currentlyLoading = $isLoading || loading; + $: currentlyLoading = $isLoading; logSetup(); let logger = new Logger("2fasetup/+page.svelte"); @@ -24,6 +24,9 @@ let code = ''; + let has_error = false; + let form_err = ''; + onMount(async () => { let session_load_info = await isAuthedSession(); if (session_load_info[0] == APIResult.Failed) { @@ -42,7 +45,6 @@ if (create_res[0] == APIResult.Failed) { logger.error(`totp create fail`); - isError = true; let err = create_res[1] as APIError; let etext = err.code; @@ -54,7 +56,8 @@ return; } - error = $t('2fasetup.error.generic', {values:{err:etext}}); + has_error = true; + error = $t('2fasetup.error.' + etext); loading = false; return; } @@ -76,7 +79,6 @@ if (create_res[0] == APIResult.Failed) { logger.error(`totp auth fail`); - isError = true; let err = create_res[1] as APIError; let etext = err.code; @@ -88,7 +90,8 @@ return; } - error = $t('2fasetup.error.generic', {values:{err:etext}}); + has_error = true; + form_err = $t('2fasetup.error.' + etext); loading = false; return; } @@ -103,17 +106,35 @@ -

{$t('2fasetup.title')}

-

{$t('2fasetup.body')}

-

{$t('2fasetup.scan')}

-
- + +
+
+
+

{$t('2fasetup.title')}

+

{$t('2fasetup.body')}

+
+
{$t('2fasetup.scan')}
+
+ +
+
+
{$t('2fasetup.code')}
+

{totp_secret}

+
+
+ + + + {#if loading} + + {:else} + + {/if} +
+ {#if has_error} +

{form_err}

+ {/if} +
+
-

{$t('2fasetup.code')}

-
{totp_secret}
-
- - - -