Skip to content

DEV-1037: feat(login): migrate to unified auth flow#237

Open
hcarneiro wants to merge 1 commit intoprojects/DEV-908-unified-loginfrom
feat/DEV-908-unified-login
Open

DEV-1037: feat(login): migrate to unified auth flow#237
hcarneiro wants to merge 1 commit intoprojects/DEV-908-unified-loginfrom
feat/DEV-908-unified-login

Conversation

@hcarneiro
Copy link
Copy Markdown
Contributor

Summary

  • Replace legacy /v1/auth/third-party endpoint with the unified /v1/auth/login?return=callback&callback=http://localhost:9001/callback contract
  • Parse ?token=<token> (new contract) instead of ?auth_token=<token> using proper URL parsing
  • Fix multi-org users: pick first org by default instead of hard-failing, print note about fliplet organization <id> to switch
  • Fix all error paths to write HTTP response + process.exit(1) (prevents browser retries that triggered duplicate errors)

Test plan

  • Run node fliplet-login.js (or fliplet login if linked) — verify browser opens to unified sign-in page
  • Sign in with email/password — verify CLI prints success and org info
  • Sign in with SSO (Google/Microsoft) — verify same flow works
  • Test with a multi-org user — verify first org is picked and note is printed
  • Test closing browser without completing — verify CLI exits cleanly

🤖 Generated with Claude Code

Replaces the legacy /v1/auth/third-party endpoint (which is being
removed from the API as part of DEV-908) with the same unified sign-in
URL the Fliplet Login widget and VS Code extension now use. The
allow-list on the API already includes http://localhost:9001/callback
so no server-side change is needed for the CLI path.

Contract change: the callback URL now receives ?token=<token>&user=...
instead of ?auth_token=<token>. Parse the token with url.parse(...).query
so we handle any additional params the API may append.

Drive-by fixes to the callback handler surfaced while testing:

- Multi-org users no longer hard-fail. The previous code rejected any
  user belonging to more than one organization with "You belong to
  multiple organizations." Now we pick the first organization by
  default and print a note telling the user how to switch afterwards
  via `fliplet list-organizations` + `fliplet organization <id>`.
- Every error path now writes an HTTP response to the browser AND
  calls process.exit(1). The old code left connections hanging, which
  caused the browser to retry and fire the callback handler twice —
  leading to the "multiple organizations" error printing twice.

package-lock.json: drift from 7.0.0 to 7.0.1 (matches package.json,
unrelated to this change).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hcarneiro hcarneiro changed the title feat(login): migrate to unified auth flow DEV-1037: feat(login): migrate to unified auth flow Apr 10, 2026
@hcarneiro hcarneiro requested review from Arpanexe and tonytlwu April 10, 2026 09:12
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