Show workers as their own labeled section in active sessions - #159
Conversation
Extract isProduction once and reuse it for emailAndPassword and cookie security, and drop the redundant inline logger.log parameter types that better-auth's own types already infer. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Login sessions from browser/desktop/mobile controllers and from the CLI worker (cyrusd) were indistinguishable in the active-sessions list. Add a nullable workerName field to the session model (set only by cyrusd, via the OAuth device-authorization grant it exclusively uses to log in) and split the UI into Controllers and Workers sections, the latter showing a count and each row labeled with its worker name and a terminal icon instead of a browser/OS parse. The CLI pushes its name via better-auth's built-in updateSession client method rather than a custom endpoint. Both login and rename treat a failed push as fatal — login removes the just-stored token and rename leaves local config untouched — so a session can never end up desynced from its worker name. See docs/adr/0023-worker-name-discriminates-login-sessions.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe change adds optional ChangesWorker session topology
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant authClient
participant BetterAuth
participant D1Session
CLI->>authClient: syncWorkerName(name)
authClient->>BetterAuth: updateSession(workerName)
BetterAuth->>D1Session: update worker_name
D1Session-->>BetterAuth: update result
BetterAuth-->>authClient: session update result
authClient-->>CLI: Result<void, string>
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/server/src/auth/options.ts`:
- Around line 34-41: Restrict the workerName configuration in the session
additionalFields definition so generic client updateSession calls cannot write
it. Add a worker-authenticated server-side update path for the CLI that accepts
only non-empty names and verifies device-authorization provenance. Update the
related ADR to describe the server-only CLI path rather than claiming generic
updateSession restricts workerName to the CLI.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ab12529-5684-4105-a0fb-e20afcef2677
📒 Files selected for processing (16)
CONTEXT.mdapps/cli/src/commands/auth/login.tsapps/cli/src/commands/config/rename.test.tsapps/cli/src/commands/config/rename.tsapps/cli/src/lib/auth.tsapps/server/drizzle.config.tsapps/server/src/auth/cli.tsapps/server/src/auth/options.tsapps/server/src/db/migrations/20260806160054_add_worker_name_to_session/migration.sqlapps/server/src/db/migrations/20260806160054_add_worker_name_to_session/snapshot.jsonapps/server/src/db/models/auth.tsapps/web/src/components/auth/security/active-session.test.tsxapps/web/src/components/auth/security/active-session.tsxapps/web/src/components/auth/security/active-sessions.test.tsxapps/web/src/components/auth/security/active-sessions.tsxdocs/adr/0023-worker-name-discriminates-login-sessions.md
Summary
cyrusd) were indistinguishable in the active-sessions settings page.workerNamefield to thesessionmodel, set only bycyrusd(the only peer type that logs in via the OAuth device-authorization grant), and split the UI into Controllers and Workers sections — the latter shows a count and each row is labeled with the worker's name and a terminal icon instead of a browser/OS parse.updateSessionclient method rather than a custom endpoint. Bothloginandrenametreat a failed push as fatal —loginremoves the just-stored token andrenameleaves local config untouched — so a session can never end up desynced from its worker name.drizzle-kit generatewas emittingDROP TABLEfor everything becausedrizzle.config.tspointed at a schema module with no top-level table exports, andauth:generatewas broken because the CLI-only auth config had no drizzle adapter for the current@better-auth/clito recognize.See
docs/adr/0023-worker-name-discriminates-login-sessions.mdfor the full design rationale.Test plan
bun run check:types(all packages)bun run test:unit(148 web/server/shared + 122 CLI tests)bun run test:integrationbun check(lint, scoped to touched files)cyrusd rename(success, server-rejects, not-logged-in) spawning the real CLI binary against a fake local serverdb:generateis idempotent afterward🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation