fix(cli): show re-login guidance when token refresh is unavailable - #359
Conversation
🧪 Testing GuideWhat this PR addressesWhen a user's access token is expired and no refresh token is available (or the refresh fails), Steps to reproduce the original issue
What to verify (expected behavior)
Note Posted by PR Testing Guide · Tag @mendral-app with feedback. |
|
✅ Linked to Linear issue ENG-2815 — status already In Progress, assigned to Michael Stolarz. Note Posted by Linear Issue Enforcer · Tag @mendral-app with feedback. |
Interaction Flow DiagramThis PR reorders the sequenceDiagram
participant User
participant CLI as bl token (CLI)
participant Creds as blaxel.LoadCredentials
participant Auth as tokenForCredentials
participant OAuth as authHeadersForCredentials
participant Client as blaxel.Client (API)
User->>CLI: bl token <workspace>
CLI->>Creds: LoadCredentials(workspace)
alt credentials missing/invalid
Creds-->>CLI: error
CLI-->>User: ❌ "bl login <workspace>"
end
Creds-->>CLI: credentials
CLI->>Auth: tokenForCredentials(ctx, workspace, credentials)
Auth->>OAuth: authHeadersForCredentials(ctx, credentials, workspace)
alt refresh fails & both tokens present
OAuth-->>Auth: error
Auth-->>CLI: ❌ "bl login <workspace>"
CLI-->>User: exit 1 + login guidance (no token printed)
end
alt token expired & no refresh token
OAuth-->>Auth: error (expired)
Auth-->>CLI: ❌ "bl login <workspace>"
CLI-->>User: exit 1 + login guidance
end
OAuth-->>Auth: headers with valid token
Auth-->>CLI: token
CLI->>Client: Workspaces.Get(workspace)
alt workspace inaccessible
Client-->>CLI: error
CLI-->>User: ❌ workspace error (token not printed)
end
Client-->>CLI: ok
CLI-->>User: ✅ print token to stdout
Summary of the new flow (before → after)
Key improvement: Expired or non-refreshable tokens now fail with clear re-login guidance before any API call is made, and tokens are never printed for inaccessible workspaces. Note Posted by PR Sequence Diagram · Tag @mendral-app with feedback. |
There was a problem hiding this comment.
LGTM
The reordering is sound: credentials are loaded first, token retrieval/refresh happens next (surfacing login guidance on failure), then the workspace access check gates output. The two error paths (refresh-failed with both tokens at line 131, expired-without-refresh at line 142) both produce actionable guidance correctly. The subprocess test pattern is standard Go practice for testing os.Exit paths.
Tag @mendral-app with feedback or questions. View session
Summary
bl tokenbl login <workspace>guidance without ever printing the tokenFixes ENG-2815
Verification
go test ./cli -count=1 -run 'Test(Token|Bearer)'make testmake lintgo build ./...Note
Reorders the
bl tokencommand logic to load and validate credentials before making the workspace API call. This ensures that expired/non-refreshable tokens produce actionable "bl login" guidance instead of cryptic API failures. Adds a login guidance message when OAuth refresh fails, and includes a subprocess-based integration test for the expired-token-without-refresh path.Written by Mendral for commit 22c4b55.