Lines 195-235javascript
197 if (!device.verification_uri) {
199 `GitHub returned unexpected response: ${JSON.stringify(device)}\n` +
200 `Check your GITHUB_CLIENT_ID in .env is correct.`
204 // Step 2 — show user the code
205 console.log("\n┌─────────────────────────────────────────┐");
206 console.log("│ Claw-Coder Login │");
207 console.log("├─────────────────────────────────────────┤");
208 console.log(`│ Open: ${device.verification_uri.padEnd(32)}│`);
209 console.log(`│ Code: ${device.user_code.padEnd(32)}│`);
210 console.log("└─────────────────────────────────────────┘\n");
212 const cmd = process.platform === "darwin" ? "open"
213 : process.platform === "win32" ? "start"
216 require("child_process").execSync(`${cmd} "${device.verification_uri}"`, { stdio: "ignore" });
219 // Step 3 — poll GitHub until user approves
220 console.log("Waiting for you to approve in the browser...\n");
221 const pollInterval = (device.interval || 5) * 1000;
222 const expires = Date.now() + device.expires_in * 1000;
224 while (Date.now() < expires) {
225 await new Promise(r => setTimeout(r, pollInterval));
227 const tokenRes = await fetch("https://github.com/login/oauth/access_token", {
229 headers: { "Content-Type": "application/json", "Accept": "application/json" },
230 body: JSON.stringify({
231 client_id: githubClientId,
232 device_code: device.device_code,
233 grant_type: "urn:ietf:params:oauth:grant-type:device_code",