diff --git a/frontend/src/components/GitHubLoginDialog.tsx b/frontend/src/components/GitHubLoginDialog.tsx index 9da41a9d..8c52b642 100644 --- a/frontend/src/components/GitHubLoginDialog.tsx +++ b/frontend/src/components/GitHubLoginDialog.tsx @@ -105,12 +105,40 @@ export function GitHubLoginDialog({ // Automatically copy code to clipboard when deviceState is set useEffect(() => { if (deviceState?.user_code) { - navigator.clipboard.writeText(deviceState.user_code); - setCopied(true); - setTimeout(() => setCopied(false), 2000); + copyToClipboard(deviceState.user_code); } }, [deviceState?.user_code]); + const copyToClipboard = async (text: string) => { + try { + if (navigator.clipboard && navigator.clipboard.writeText) { + await navigator.clipboard.writeText(text); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } else { + // Fallback for environments where clipboard API is not available + const textArea = document.createElement('textarea'); + textArea.value = text; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { + document.execCommand('copy'); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } catch (err) { + console.warn('Copy to clipboard failed:', err); + } + document.body.removeChild(textArea); + } + } catch (err) { + console.warn('Copy to clipboard failed:', err); + } + }; + return ( @@ -166,11 +194,7 @@ export function GitHubLoginDialog({