| 47 | } |
| 48 | |
| 49 | function renderDeviceCodeBox( |
| 50 | userCode: string, |
| 51 | verificationUri: string, |
| 52 | verificationUriComplete: string | undefined |
| 53 | ): string { |
| 54 | const codeLine = `${pc.dim("Your one-time code:")}\n\n ${pc.green(pc.bold(userCode))}`; |
| 55 | // Per RFC 8628 §3.3, even when verification_uri_complete is available we |
| 56 | // still show the bare verification_uri so users on screen readers / paper |
| 57 | // can type it manually. |
| 58 | const linkLine = verificationUriComplete |
| 59 | ? `${pc.dim("Open this link to approve:")}\n${pc.cyan(verificationUriComplete)}\n\n${pc.dim("Or visit")} ${pc.cyan(verificationUri)} ${pc.dim("and enter the code above.")}` |
| 60 | : `${pc.dim("Visit:")} ${pc.cyan(verificationUri)}`; |
| 61 | return boxen(`${codeLine}\n\n${linkLine}`, { |
| 62 | title: "Sign in to Context7", |
| 63 | titleAlignment: "left", |
| 64 | padding: 1, |
| 65 | margin: { top: 1, bottom: 1, left: 2, right: 2 }, |
| 66 | borderStyle: "round", |
| 67 | borderColor: "gray", |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | /** Prints a prompt and resolves on the next keypress. No-op when stdin isn't a TTY. */ |
| 72 | function waitForEnter(prompt: string): Promise<void> { |