mirror of
				https://github.com/ClusterCockpit/cc-backend
				synced 2025-11-03 17:15:06 +01:00 
			
		
		
		
	fix Generate JWT as user doesn't work #327
This commit is contained in:
		@@ -43,10 +43,33 @@
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let displayCheck = false;
 | 
			
		||||
    function clipJwt() {
 | 
			
		||||
      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 @@
 | 
			
		||||
                    <p class="mt-2">
 | 
			
		||||
                        Your token is displayed on the right. Press this button to copy it to the clipboard.
 | 
			
		||||
                    </p>
 | 
			
		||||
                    {#if displayCheck}
 | 
			
		||||
                        <p class="mt-2">
 | 
			
		||||
                            <span class="text-success">Copied!</span>
 | 
			
		||||
                        </p>
 | 
			
		||||
                    {/if}
 | 
			
		||||
                {:else}
 | 
			
		||||
                    <Button color="success" on:click={getUserJwt(username)}>
 | 
			
		||||
                        Generate JWT for '{username}'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user