modified: frontend/src/pages/ApiKeys.tsx

This commit is contained in:
GEgorov
2025-10-07 00:55:15 +03:00
parent 80db44e50e
commit 566f97f177

View File

@@ -56,9 +56,33 @@ export default function ApiKeys() {
},
});
const copyToClipboard = (key: string) => {
navigator.clipboard.writeText(key);
const copyToClipboard = async (key: string) => {
try {
// Try modern clipboard API first (requires HTTPS or localhost)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(key);
toast.success('API ключ скопирован в буфер обмена');
} else {
// Fallback for HTTP
const textArea = document.createElement('textarea');
textArea.value = key;
textArea.style.position = 'fixed';
textArea.style.left = '-999999px';
textArea.style.top = '-999999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
toast.success('API ключ скопирован в буфер обмена');
} catch (err) {
toast.error('Не удалось скопировать');
}
textArea.remove();
}
} catch (err) {
toast.error('Не удалось скопировать');
}
};
const toggleReveal = (id: string) => {