Skip to content

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

Open
hcarneiro wants to merge 5 commits 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 5 commits 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
hcarneiro and others added 4 commits April 14, 2026 19:37
The organizations module captured auth_token at require-time. When
`fliplet login` runs as a single process — sign-in happens via a
browser callback AFTER the module was loaded — the captured token
was whatever was in configstore at startup (null on first login),
and the subsequent getOrganizationsList() call failed with "You must
login first with: fliplet login".

Moving the user/auth_token lookup inside the function makes it read
the up-to-date configstore value every call.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New developer documentation for the Fliplet.Auth SDK (fliplet-auth
package). Covers:

- signIn / signOut / currentUser / isSignedIn / getToken / onChange
- Common patterns (gated screens, profile display, sign-out button,
  authenticated API requests, reacting to auth state changes)
- What Fliplet.Auth does NOT do (no user creation from apps, no
  app-specific user data management)

Also registers the doc in the API-Documentation.md index under the
alphabetical "Auth" entry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Review pass against references/style-guide.md and references/dev-docs-rules.md:

- Add YAML frontmatter with description field (required for dev docs)
- Remove all horizontal rules (---) per style guide
- Promote the "can't create users from apps" caveat to a <p class="warning">
  callout in "Before you start" — previously buried at the end
- Disambiguate Fliplet.Auth vs Fliplet.User vs data source login on
  first use rather than only mentioning at the end
- First signIn() example includes .catch() so copy-paste is safe
- Make Error rejection cases explicit with exact message strings
- Remove `region` from the documented currentUser() shape (internal
  detail derived from token prefix, not part of public contract)
- Clarify signIn() vs currentUser() return-shape asymmetry inline at
  the point of discovery rather than in a separate "gotchas" section
- Add "if server-side logout fails" behaviour note under signOut()
- All code examples guard against null token / missing user per
  dev-docs-rules ("Code examples must match documented constraints")

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a link to the Fliplet.Auth reference doc in the JS API →
Libraries section of the sidebar, alphabetically between Core and
Communicate, with the NEW label.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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