-
Notifications
You must be signed in to change notification settings - Fork 8
feat: auto-fill auth code when opening KiloClaw gateway #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9485bda
32e32c2
7296c4a
37aa769
d023ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 'use client'; | ||
|
|
||
| import { useCallback, useState } from 'react'; | ||
| import { ExternalLink, Loader2 } from 'lucide-react'; | ||
| import { toast } from 'sonner'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { useAccessCode } from '../hooks/useAccessCode'; | ||
|
|
||
| const OPEN_BUTTON_ACCENT_CLASS = | ||
| 'animate-pulse-once bg-[oklch(95%_0.15_108)] text-black shadow-[0_0_20px_rgba(237,255,0,0.3)] ring-[oklch(95%_0.15_108)]/20 transition-all duration-500 ease-in-out hover:bg-[oklch(95%_0.15_108)]/90 hover:ring-[oklch(95%_0.15_108)]/40'; | ||
|
|
||
| export function OpenClawButton({ canShow, gatewayUrl }: { canShow: boolean; gatewayUrl: string }) { | ||
| const { isGenerating, generateAccessCode } = useAccessCode(); | ||
| const [isOpening, setIsOpening] = useState(false); | ||
|
|
||
| // Open the window synchronously (in the click handler's call stack) to avoid | ||
| // popup blockers, then navigate it once the access code arrives. | ||
| const openWithAutoAuth = useCallback(async () => { | ||
| setIsOpening(true); | ||
| const win = window.open('about:blank', '_blank'); | ||
| try { | ||
| const code = await generateAccessCode(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [WARNING]: One-time access code wasted when popup is blocked If Consider checking const win = window.open('about:blank', '_blank');
if (!win) {
toast.error('Popup blocked — please allow popups for this site');
setIsOpening(false);
return;
}
try {
const code = await generateAccessCode();
... |
||
| if (code && win) { | ||
| const url = new URL(gatewayUrl, window.location.origin); | ||
| url.searchParams.set('auth_code', code); | ||
| win.location.href = url.toString(); | ||
| } else { | ||
| win?.close(); | ||
| } | ||
| } catch { | ||
| win?.close(); | ||
| toast.error('Failed to open KiloClaw — invalid gateway URL'); | ||
| } finally { | ||
| setIsOpening(false); | ||
| } | ||
| }, [gatewayUrl, generateAccessCode]); | ||
|
|
||
| if (!canShow) return null; | ||
|
|
||
| return ( | ||
| <Button | ||
| variant="primary" | ||
| className={OPEN_BUTTON_ACCENT_CLASS} | ||
| disabled={isOpening || isGenerating} | ||
| onClick={openWithAutoAuth} | ||
| > | ||
| {isOpening ? ( | ||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
| ) : ( | ||
| <ExternalLink className="mr-2 h-4 w-4" /> | ||
| )} | ||
| {isOpening ? 'Opening...' : 'Open'} | ||
| </Button> | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.