fix(ui): fix method to copy debug token (#1951)

This commit is contained in:
Delirium 2024-03-12 17:46:20 +01:00 committed by GitHub
parent f9d915d18a
commit 18fa90fe7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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')
}