Repository navigation
Commit 87dd140
fix: connect the right Apify account in
> [!NOTE]
> **TL;DR** — `apify create --source github` connected GitHub to the
wrong Apify account for anyone logged in as an organization. The connect
link omitted the `routePrefix` query parameter, so Console verified the
OAuth code as the personal account behind the organization and the CLI
waited for an integration that could never appear. Fixed by sending the
prefix, and by naming the account the CLI is connecting so a grant that
lands elsewhere is visible instead of silent.
Fixes #1370.
### What changed
`src/lib/git-source/gitSource.ts`
- `getGitConnectUrl` sends `routePrefix=/organization/<id>` for an
organization login, encoded the way Console encodes it. The callback
page decodes it and navigates to the organization route, so the code is
verified as the organization.
- New `GitAccount` type and `toGitAccount()`, which keeps id, username
and `organizationOwnerUserId` and leaves the token out of the flow
options.
- The wait loop re-reads which grant is missing on every poll.
Authorizing makes the integration appear with no workspaces, and only
installing the app fills them, so the install URL is offered as soon as
authorization lands instead of after the 3-minute timeout. A URL that
has already been opened is never opened twice.
- The wait line and the `notAuthorized` / `noWorkspace` errors name the
Apify account, so a grant that landed on another account is visible
instead of silent.
- `getGitStopUrl` and `buildGitSourceNextSteps` take the account too, so
the recovery URL is not the same dead end.
`src/commands/create.ts` reads the account after
`getLoggedClientOrThrow()`, which refreshes `auth.json` from the token
the run resolved, and threads it through the flow, the next steps and
the `--json` `gitConnectUrl`.
### Reviewer notes
- The prefix is double-encoded on the wire. This matches Console's own
implementation, which does `encodeURIComponent(prefix)` and then encodes
again into the query it builds; the callback page decodes once by
parsing the query and once more with `decodeURIComponent`. Verified
against the deployed Console bundle, not inferred.
- `type: USER` routes each get a generated `/organization/:viewedUserId`
twin, and `viewedUserId` from the pathname selects the token the
callback verifies under. That is what binds the grant to the
organization.
- Nothing else changes for a personal login. There is a test asserting
the URL stays byte-identical to before.
- Console-side, not fixed here: the callback page calls
`window.close()`, which browsers ignore for a tab the CLI opened with
`open()`. Console's own flow uses a 900×700 popup, where close works.
The CLI cannot get a popup, so the user is left on a page with a dead
Close button.
### Verification
Verified live on an organization login, with Console's UI left on the
personal account to prove the routing does not depend on it. `apify
create --source github` sends the grant to the organization, and
workspace selection proceeds.
### Follow-up
A second bug surfaced while testing this one: the CLI guesses which
GitHub grant is missing from an API state where the two possibilities
are indistinguishable, so it can offer a link that never resolves. That
is unrelated to redirects and hits personal accounts too. It is fixed in
a follow-up PR stacked on this branch.
### Checks
`lint`, `format`, `build`, `test:local` (493 passed, 4 skipped). No docs
regen — no flag, arg or description changed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>apify create --source github (#1371)1 parent d3f7102 commit 87dd140
3 files changed
Lines changed: 114 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
302 | 304 | | |
303 | 305 | | |
304 | 306 | | |
| 307 | + | |
| 308 | + | |
305 | 309 | | |
306 | 310 | | |
307 | 311 | | |
| |||
343 | 347 | | |
344 | 348 | | |
345 | 349 | | |
| 350 | + | |
346 | 351 | | |
347 | 352 | | |
348 | 353 | | |
| |||
567 | 572 | | |
568 | 573 | | |
569 | 574 | | |
| 575 | + | |
570 | 576 | | |
571 | 577 | | |
572 | 578 | | |
| |||
586 | 592 | | |
587 | 593 | | |
588 | 594 | | |
589 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
590 | 598 | | |
591 | 599 | | |
592 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
87 | 110 | | |
88 | | - | |
| 111 | + | |
89 | 112 | | |
90 | 113 | | |
91 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
92 | 119 | | |
93 | 120 | | |
94 | 121 | | |
| |||
208 | 235 | | |
209 | 236 | | |
210 | 237 | | |
211 | | - | |
| 238 | + | |
212 | 239 | | |
213 | 240 | | |
214 | 241 | | |
| |||
223 | 250 | | |
224 | 251 | | |
225 | 252 | | |
226 | | - | |
227 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
228 | 272 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 273 | + | |
233 | 274 | | |
234 | 275 | | |
235 | 276 | | |
| |||
238 | 279 | | |
239 | 280 | | |
240 | 281 | | |
| 282 | + | |
241 | 283 | | |
242 | 284 | | |
243 | 285 | | |
| |||
426 | 468 | | |
427 | 469 | | |
428 | 470 | | |
| 471 | + | |
| 472 | + | |
429 | 473 | | |
430 | 474 | | |
431 | 475 | | |
| |||
444 | 488 | | |
445 | 489 | | |
446 | 490 | | |
| 491 | + | |
447 | 492 | | |
448 | 493 | | |
449 | 494 | | |
| |||
465 | 510 | | |
466 | 511 | | |
467 | 512 | | |
468 | | - | |
| 513 | + | |
469 | 514 | | |
470 | 515 | | |
471 | 516 | | |
472 | 517 | | |
| 518 | + | |
473 | 519 | | |
474 | | - | |
| 520 | + | |
475 | 521 | | |
476 | 522 | | |
477 | | - | |
| 523 | + | |
478 | 524 | | |
479 | 525 | | |
480 | 526 | | |
| |||
573 | 619 | | |
574 | 620 | | |
575 | 621 | | |
576 | | - | |
577 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
578 | 628 | | |
579 | 629 | | |
580 | 630 | | |
| |||
592 | 642 | | |
593 | 643 | | |
594 | 644 | | |
| 645 | + | |
595 | 646 | | |
596 | 647 | | |
597 | 648 | | |
| |||
604 | 655 | | |
605 | 656 | | |
606 | 657 | | |
| 658 | + | |
607 | 659 | | |
608 | 660 | | |
609 | 661 | | |
| |||
613 | 665 | | |
614 | 666 | | |
615 | 667 | | |
616 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
617 | 672 | | |
618 | 673 | | |
619 | 674 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
73 | 98 | | |
74 | 99 | | |
75 | 100 | | |
| |||
157 | 182 | | |
158 | 183 | | |
159 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
160 | 196 | | |
161 | 197 | | |
162 | 198 | | |
| |||
0 commit comments