({
onSuccess,
onCancel
}: OAuthFlowStepProps)
| 34 | }; |
| 35 | const PASTE_HERE_MSG = 'Paste code here if prompted > '; |
| 36 | export function OAuthFlowStep({ |
| 37 | onSuccess, |
| 38 | onCancel |
| 39 | }: OAuthFlowStepProps): React.ReactNode { |
| 40 | const [oauthStatus, setOAuthStatus] = useState<OAuthStatus>({ |
| 41 | state: 'starting' |
| 42 | }); |
| 43 | const [oauthService] = useState(() => new OAuthService()); |
| 44 | const [pastedCode, setPastedCode] = useState(''); |
| 45 | const [cursorOffset, setCursorOffset] = useState(0); |
| 46 | const [showPastePrompt, setShowPastePrompt] = useState(false); |
| 47 | const [urlCopied, setUrlCopied] = useState(false); |
| 48 | const timersRef = useRef<Set<NodeJS.Timeout>>(new Set()); |
| 49 | // Separate ref so startOAuth's timer clear doesn't cancel the urlCopied reset |
| 50 | const urlCopiedTimerRef = useRef<NodeJS.Timeout | undefined>(undefined); |
| 51 | const terminalSize = useTerminalSize(); |
| 52 | const textInputColumns = Math.max(50, terminalSize.columns - PASTE_HERE_MSG.length - 4); |
| 53 | function handleKeyDown(e: KeyboardEvent): void { |
| 54 | if (oauthStatus.state !== 'error') return; |
| 55 | e.preventDefault(); |
| 56 | if (e.key === 'return' && oauthStatus.toRetry) { |
| 57 | setPastedCode(''); |
| 58 | setCursorOffset(0); |
| 59 | setOAuthStatus({ |
| 60 | state: 'about_to_retry', |
| 61 | nextState: oauthStatus.toRetry |
| 62 | }); |
| 63 | } else { |
| 64 | onCancel(); |
| 65 | } |
| 66 | } |
| 67 | async function handleSubmitCode(value: string, url: string) { |
| 68 | try { |
| 69 | // Expecting format "authorizationCode#state" from the authorization callback URL |
| 70 | const [authorizationCode, state] = value.split('#'); |
| 71 | if (!authorizationCode || !state) { |
| 72 | setOAuthStatus({ |
| 73 | state: 'error', |
| 74 | message: 'Invalid code. Please make sure the full code was copied', |
| 75 | toRetry: { |
| 76 | state: 'waiting_for_login', |
| 77 | url |
| 78 | } |
| 79 | }); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | // Track which path the user is taking (manual code entry) |
| 84 | logEvent('tengu_oauth_manual_entry', {}); |
| 85 | oauthService.handleManualAuthCodeInput({ |
| 86 | authorizationCode, |
| 87 | state |
| 88 | }); |
| 89 | } catch (err: unknown) { |
| 90 | logError(err); |
| 91 | setOAuthStatus({ |
| 92 | state: 'error', |
| 93 | message: (err as Error).message, |
nothing calls this directly
no test coverage detected