From 18fa90fe7c905fb98ff469eb2f236dfc04b1559b Mon Sep 17 00:00:00 2001 From: Delirium Date: Tue, 12 Mar 2024 17:46:20 +0100 Subject: [PATCH] fix(ui): fix method to copy debug token (#1951) --- frontend/app/store.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/app/store.js b/frontend/app/store.js index 2e4165389..0b8cf7278 100644 --- a/frontend/app/store.js +++ b/frontend/app/store.js @@ -28,13 +28,28 @@ store.subscribe(() => { }); }); -async function copyToClipboard(text) { +function copyToClipboard(text) { + const textArea = document.createElement("textarea"); + textArea.value = text; + + // Avoid scrolling to bottom + textArea.style.top = "0"; + textArea.style.left = "0"; + textArea.style.position = "fixed"; + + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { - await navigator.clipboard.writeText(text); - console.log('Copied to clipboard'); + const successful = document.execCommand('copy'); + const msg = successful ? 'successful' : 'unsuccessful'; + console.log('Token copy ' + msg); } catch (err) { - console.error('Could not copy text: ', err); + console.error('unable to copy', err); } + + document.body.removeChild(textArea); } @@ -42,7 +57,7 @@ window.getJWT = () => { const jwtToken = storage.state().user?.jwt ? JSON.stringify(storage.state().user?.jwt) : null if (jwtToken) { console.log(jwtToken); - void copyToClipboard(jwtToken) + copyToClipboard(jwtToken) } else { console.log('not logged in') }