From 95d8062b0044bdc47290d49120b53229d0c4f876 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Thu, 30 Jan 2025 11:10:50 +0100 Subject: [PATCH 1/2] fix Generate JWT as user doesn't work #327 --- .../src/config/user/UserOptions.svelte | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/web/frontend/src/config/user/UserOptions.svelte b/web/frontend/src/config/user/UserOptions.svelte index be7f368..0cdbe9f 100644 --- a/web/frontend/src/config/user/UserOptions.svelte +++ b/web/frontend/src/config/user/UserOptions.svelte @@ -43,10 +43,33 @@ } } + let displayCheck = false; function clipJwt() { - navigator.clipboard - .writeText(jwt) - .catch((reason) => console.error(reason)); + displayCheck = true; + // Navigator clipboard api needs a secure context (https) + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard + .writeText(jwt) + .catch((reason) => console.error(reason)); + } else { + // Workaround: Create, Fill, And Copy Content of Textarea + const textArea = document.createElement("textarea"); + textArea.value = jwt; + textArea.style.position = "absolute"; + textArea.style.left = "-999999px"; + document.body.prepend(textArea); + textArea.select(); + try { + document.execCommand('copy'); + } catch (error) { + console.error(error); + } finally { + textArea.remove(); + } + } + setTimeout(function () { + displayCheck = false; + }, 1000); } const dispatch = createEventDispatcher(); @@ -120,6 +143,11 @@

Your token is displayed on the right. Press this button to copy it to the clipboard.

+ {#if displayCheck} +

+ Copied! +

+ {/if} {:else}