You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(auth): enforce auth by default in buildCommand (#611)
## Summary
All commands now require authentication by default. `buildCommand`
checks `isAuthenticated()` before invoking the command function and
throws `AuthError("not_authenticated")` if no token exists — this feeds
into the existing auto-auth middleware that prompts login and retries.
Previously each command had to manually guard auth or rely on an API
call failing deep in execution. `sentry init` in particular had no auth
check at all and would proceed into the wizard flow before eventually
failing.
## Changes
Added `auth?: boolean` to `buildCommand` options (defaults `true`). The
check runs before the generator, so the auto-auth middleware in `cli.ts`
catches it and kicks off the interactive login flow on unauthenticated
runs.
Commands that intentionally work without a token opt out with `auth:
false`:
- `auth login`, `auth logout`, `auth refresh`, `auth status`
- `help`, `schema`
- `cli fix`, `cli setup`, `cli upgrade`, `cli feedback`
With this in place, the redundant explicit `isAuthenticated()` checks in
`auth whoami` and `auth token` were removed.
## Test Plan
- `sentry init` (unauthenticated) → should immediately prompt
"Authentication required. Starting login flow..."
- `sentry auth login` (unauthenticated) → should work normally
- `sentry auth status` (unauthenticated) → should show "not
authenticated" cleanly, no login prompt
- `sentry auth logout` (unauthenticated) → should return "Not currently
authenticated."
- `SENTRY_AUTH_TOKEN=xxx sentry init` → no auth prompt, proceeds
normally
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments