Commit 8e8973d
fix(init): prompt for team selection when user belongs to multiple teams (#621)
## Summary
`sentry init` failed for most new users — people who just signed up on
sentry.io and ran the wizard. The root causes:
1. The CLI's OAuth token lacked `team:write` scope, so even org Owners
couldn't create teams
2. Team resolution only happened deep in the workflow (after minutes of
AI analysis), not upfront
3. The 0-teams case failed with a cryptic 403 error
Now all team scenarios are resolved early in
`resolvePreSpinnerOptions()`, right after org selection and before the
spinner starts. Also added `team:write` to the OAuth scopes.
## All team scenarios handled
| Scenario | Behavior |
|---|---|
| **0 teams** | Auto-creates a team called "default". On failure (e.g.
missing permissions), shows friendly error with link to create a team in
the UI |
| **1 team** | Auto-selects it silently |
| **Multiple teams, user is member of 1** | Auto-selects the member team
|
| **Multiple teams, user is member of several** | Shows interactive
prompt to pick one |
| **Multiple teams, user is member of several + `--yes`** | Auto-selects
the first member team |
| **Multiple teams, user is member of none** (new user) | Shows
interactive prompt with all org teams |
| **Multiple teams, user is member of none + `--yes`** | Auto-selects
the first org team |
| **`--team` flag provided** | Uses it directly, skips all resolution |
| **API error fetching teams** | Silently falls through to existing
`resolveOrCreateTeam` as fallback |
## Test plan
- [ ] `sentry login` then `sentry init` on org with 0 teams →
auto-creates "default" team, proceeds
- [ ] `sentry init` on org with 1 team → no prompt, auto-selects
- [ ] `sentry init` on org with multiple teams → shows team selection
prompt
- [ ] `sentry init --team <slug>` → skips prompt
- [ ] `sentry init --yes` on org with multiple teams → auto-selects
first member team
- [ ] Cancel team prompt (Ctrl+C) → clean exit
- [ ] Existing users need `sentry login` again to get the new
`team:write` scope
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 42c2ca8 commit 8e8973d
File tree
3 files changed
+102
-0
lines changed- src/lib
- init
- test/lib/init
3 files changed
+102
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
274 | 277 | | |
275 | 278 | | |
276 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
277 | 287 | | |
278 | 288 | | |
279 | 289 | | |
| |||
401 | 411 | | |
402 | 412 | | |
403 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
404 | 473 | | |
405 | 474 | | |
406 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| |||
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| 72 | + | |
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
| |||
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
81 | 92 | | |
82 | 93 | | |
83 | 94 | | |
| |||
153 | 164 | | |
154 | 165 | | |
155 | 166 | | |
| 167 | + | |
156 | 168 | | |
157 | 169 | | |
158 | 170 | | |
| |||
183 | 195 | | |
184 | 196 | | |
185 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
186 | 213 | | |
187 | 214 | | |
188 | 215 | | |
| |||
201 | 228 | | |
202 | 229 | | |
203 | 230 | | |
| 231 | + | |
204 | 232 | | |
205 | 233 | | |
206 | 234 | | |
| |||
213 | 241 | | |
214 | 242 | | |
215 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
216 | 248 | | |
217 | 249 | | |
218 | 250 | | |
| |||
0 commit comments