Skip to content

refactor(auth): refresh dcd login sessions through the API, not Supabase - #313

Merged
riglar merged 3 commits into
devfrom
refactor/refresh-through-api
Nov 17, 2026
Merged

riglar merged 3 commits into
devfrom
refactor/refresh-through-api

Conversation

@riglar

@riglar riglar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

What

The CLI refreshed its dcd login session by calling Supabase Auth directly, with a publishable key fetched from the API. It now posts the refresh token to the API's POST /cli-login/refresh, and the API does the refresh.

This is the second step in moving the CLI's auth off direct Supabase calls (the first was #312). After this, dcd login sessions need no Supabase key at all.

How errors map

API answer Meaning CLI does
200 New session Stores it, as before
401 + Supabase code Token refused Final: tells the user to run dcd login. The existing friendly messages for session_expired, session_not_found and refresh_token_not_found are kept
400 Bad request (empty token) Final
404, 429, 5xx, network error, non-JSON page Might work later Keeps the stored session and retries next time

A failed refresh never deletes the stored session. That hasn't changed.

The request also carries the CLI's identity headers (x-dcd-cli-version and the CI headers), like every other API call.

⚠️ Merge order

Draft until the API endpoint is live in production. A CLI released before then would get a 404 on every refresh. The 404 is treated as retryable, so nobody is logged out, but sessions would stop renewing after an hour.

Testing

  • New test/unit/cli-auth-gateway.test.ts covers the request shape, the success path, each refusal message, and every retryable case.
  • Moved the old Supabase-specific refresh tests out of supabase-key.test.ts.
  • pnpm typecheck, pnpm lint, pnpm test:unit (573 passing).

🤖 Generated with Claude Code

…abase

The CLI refreshed its session by calling Supabase Auth with a publishable
key fetched from the API. It now posts the refresh token to the API's
POST /cli-login/refresh, which does the refresh server-side.

- 401 (Supabase refused the token) and 400 are final: run `dcd login`.
  The friendly messages for session_expired / session_not_found /
  refresh_token_not_found are kept.
- Network errors, 404, 429 and 5xx keep the stored session for a retry.
- Sends the CLI identity headers, like every other API call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Code review

Skipped: this PR is still a draft (the description says it stays a draft until the API's POST /cli-login/refresh endpoint is live in production). Re-run the review once it is marked ready.

🤖 Generated with Claude Code

A 200 whose body is not JSON (a proxy page, say) made res.json() throw a
plain SyntaxError. It now throws a retryable SessionRefreshError, like the
other might-work-later cases, so the user sees a clear message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@riglar
riglar marked this pull request as ready for review November 17, 2026 11:55
@claude

claude Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@riglar
riglar merged commit ec778b2 into dev Nov 17, 2026
9 checks passed
@riglar
riglar deleted the refactor/refresh-through-api branch November 17, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant