Skip to content

feat(auth): remember last workspace and skip Auth0 workspace prompt on login - #34

Merged
filipmyllari merged 1 commit into
mainfrom
feat/remember-last-workspace
Aug 20, 2026
Merged

feat(auth): remember last workspace and skip Auth0 workspace prompt on login#34
filipmyllari merged 1 commit into
mainfrom
feat/remember-last-workspace

Conversation

@filipmyllari

Copy link
Copy Markdown
Collaborator

What

Interactive logins currently always route the user through Auth0's workspace-id prompt because the authorize URL never includes an organization parameter. This PR makes the CLI remember the workspace after a successful login and pass it along next time:

  • After a successful token exchange, the Auth0 organization identifier (org_id claim, falling back to https://confidence.dev/org_login_id) is persisted to $TMPDIR/confidence_organization, next to the existing token files, with the same 0600 mode.
  • Subsequent interactive logins pass it as the organization parameter in the authorize URL, so Auth0 skips the workspace prompt. Signup stays org-less — the signup client is unaffected.
  • Escape hatches:
    • CONFIDENCE_ORGANIZATION env var overrides the remembered value (to log into a different workspace).
    • If Auth0 returns an error on the callback while an organization was passed (e.g. a stale org), the callback responds with a 302 back to the authorize endpoint without the organization parameter — one retry instead of failing hard.
  • scripts/clean-dev-env.sh --auth now also removes the remembered organization.

Why now

This composes with the planned Auth0 "Prompt for Credentials" flip: after that flip Auth0 itself no longer prompts for a workspace id, but passing organization still skips the post-login workspace picker — so remembering the last workspace keeps repeat logins one-click either way.

Tests

New __tests__/lib/auth.test.ts exercises the real PKCE flow (real callback server, MSW for the token exchange, mocked browser opener) and covers:

  • no organization on first login
  • org persisted after login and included in the authorize URL on the next login (org_id and org_login_id fallback)
  • CONFIDENCE_ORGANIZATION env override
  • signup never includes organization
  • retry without organization when Auth0 returns an error

pnpm qa (typecheck + lint + 114 tests) and pnpm test:e2e (36 tests) pass.

🤖 Generated with Claude Code

…n login

After a successful token exchange, persist the Auth0 organization
(org_id claim, falling back to https://confidence.dev/org_login_id)
next to the existing token files. Subsequent interactive logins pass
it as the organization parameter to the authorize endpoint so Auth0
skips the workspace-id prompt. Signup stays org-less.

The CONFIDENCE_ORGANIZATION env var overrides the remembered value,
and an Auth0 error on the callback triggers one retry without the
organization parameter instead of failing hard.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@filipmyllari
filipmyllari marked this pull request as ready for review August 19, 2026 06:31

@bespoyasov bespoyasov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@filipmyllari
filipmyllari merged commit 2cf846f into main Aug 20, 2026
3 checks passed
@filipmyllari
filipmyllari deleted the feat/remember-last-workspace branch August 20, 2026 07: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.

2 participants