Skip to content

Conversation

@nicknisi
Copy link
Member

@nicknisi nicknisi commented Feb 10, 2026

Summary

Adds workos doctor — a diagnostic command that detects common WorkOS integration issues in one command. DSE team spends significant time in support conversations gathering basic diagnostic information ("What SDK?", "What version?", "Redirect URI?"). This command automates that info-gathering so customers can run a single command and share the output.

What it does

Runs a suite of diagnostic checks against the user's project:

  • SDK detection — Finds installed WorkOS SDK (@workos/*, @workos-inc/*, workos), reports version, checks npm registry for latest
  • Framework detection — Identifies Next.js (app/pages router variant), React Router, TanStack Start, Remix, Express
  • Runtime info — Node.js version, package manager + version
  • Environment config — Checks .env/.env.local for WORKOS_API_KEY, WORKOS_CLIENT_ID, WORKOS_REDIRECT_URI, WORKOS_COOKIE_DOMAIN, WORKOS_BASE_URL. Identifies staging vs production from key prefix
  • API connectivity — Tests reachability + latency to api.workos.com
  • Credential validation — Validates API key against WorkOS API (staging only, never production)
  • Dashboard settings — Fetches auth methods, MFA policy, session timeout, org count (staging only)
  • Redirect URI inference — Infers expected callback URI from framework detection when not explicitly configured
  • Issue detection — Every detected issue includes specific remediation steps and docs links

CLI flags

Flag Description
--json Output report as JSON (machine-readable for future tooling)
--copy Copy report to clipboard
--verbose Include additional diagnostic details
--skip-api Offline mode — skip all API calls
--install-dir Target a specific project directory

Security

  • API keys are never displayed — only status (configured / not set) and type (staging / production)
  • Client IDs are truncated (client_01J...7KM)
  • Production API keys are never sent to any API endpoint
  • Raw credentials are kept in an internal-only type (EnvironmentRaw) and excluded from report output

Exit codes

  • 0 — healthy, no errors
  • 1 — critical issues found (or doctor itself failed)

Architecture

src/
├── commands/doctor.ts          # CLI handler (yargs → runDoctor → outputReport)
├── doctor/
│   ├── index.ts                # Orchestrator: runs checks, detects issues, outputs report
│   ├── types.ts                # All type definitions (DoctorReport, Issue, SdkInfo, etc.)
│   ├── issues.ts               # Issue detection rules + remediation definitions
│   ├── output.ts               # Terminal formatter (chalk, emoji indicators)
│   ├── json-output.ts          # JSON serializer
│   ├── clipboard.ts            # Cross-platform clipboard (pbcopy/xclip/clip.exe)
│   └── checks/
│       ├── sdk.ts              # SDK detection + npm registry latest version
│       ├── framework.ts        # Framework detection + Next.js variant
│       ├── runtime.ts          # Node.js + package manager detection
│       ├── environment.ts      # .env/.env.local parsing via dotenv
│       ├── connectivity.ts     # API health check + latency
│       └── dashboard.ts        # Dashboard API calls + credential validation
└── bin.ts                      # yargs command registration

Checks run concurrently via Promise.all where possible (SDK, framework, runtime, connectivity), then sequential for checks that depend on environment results (credential validation, dashboard settings).

Success criteria from contract

  • Runs in any Node.js project with WorkOS SDK installed
  • Detects SDK name, version, and latest available
  • Detects Node.js runtime version
  • Detects framework and version
  • Detects package manager
  • Reports environment configuration (API key status, Client ID, base URL)
  • Identifies staging vs production from API key prefix
  • Tests API connectivity and latency
  • Fetches dashboard settings for staging environments
  • Clean terminal output with indicators
  • JSON output via --json
  • --copy flag for clipboard
  • Each issue includes remediation steps or docs links

Introduces a new diagnostic command that checks:
- SDK detection and version status
- Framework detection (Next.js, React Router, etc.)
- Runtime info (Node.js, package manager)
- Environment variables (API key, client ID)
- API connectivity and latency

Outputs actionable remediation steps for any issues found.
Supports --json for scripting and --skip-api for offline mode.
…validation

Phase 2 enhancements to the doctor command:
- Fetch dashboard settings from WorkOS API (staging only, production blocked)
- Validate credentials against /organizations endpoint
- Detect redirect URI mismatches between code and dashboard
- Add --json flag for machine-readable output
- Add --verbose flag for additional diagnostic details
- Add --copy flag for cross-platform clipboard support
- Support both @workos/* and @workos-inc/* SDK package scopes
- Load environment variables from project's .env and .env.local files
…ion comparison

- Use dotenv parser for proper .env handling (multiline, exports, inline comments)
- Normalize redirect URIs before comparison (trailing slashes, localhost variants)
- Handle prerelease/workspace versions gracefully in outdated check
- Surface dashboard API errors instead of failing silently
The mismatch may be intentional or dashboard data may be incomplete.
- Compute expected redirect URI from framework callback path + detected port
- Add source tracking ('env' vs 'inferred') for redirect URI
- Fix TanStack Start detection (check @tanstack/react-start before @tanstack/react-router)
- Remove version number from doctor header (it's part of the CLI, not standalone)
- Use array for framework detection order to guarantee specificity
WorkOS API doesn't expose an endpoint to list configured redirect URIs.
The management API only supports POST (create), not GET (list).

- Remove false mismatch warnings
- Show expected redirect URI with note to verify manually in dashboard
- Remove duplicate CredentialValidation interface from dashboard.ts
  (import from types.ts instead)
- Merge 3 redundant /organizations?limit=1 calls into 1 by folding
  credential validation into fetchDashboardSettings
- Pass resolved project env base URL to connectivity check instead of
  reading process.env directly
- Fix cross-platform copy hint (--copy flag instead of pbcopy)
@nicknisi nicknisi merged commit 8c3e093 into main Feb 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant