Skip to content

feat: add multiple auth modes#229

Merged
antfu merged 17 commits intomainfrom
antfu/human-readable-auth
Mar 19, 2026
Merged

feat: add multiple auth modes#229
antfu merged 17 commits intomainfrom
antfu/human-readable-auth

Conversation

@antfu
Copy link
Member

@antfu antfu commented Mar 18, 2026

Description

close #223

This PR implements human-readable auth IDs and multiple authentication modes for Vite DevTools:

Features:

  1. Human-readable auth IDs — Replace random nanoid with human-id library, generating IDs like apple-banana-something-words for better UX
  2. Pre-configured auth passwords — Add clientAuthPasswords: string[] config option to auto-approve matching clients without terminal prompts
  3. Auth URL endpoint — Server generates temporary auth IDs for one-click browser authorization via /.devtools/auth?id=xxx, printed in terminal prompt
  4. Terminal prompt abort — Auth prompt aborts automatically on timeout (60s), URL-based auth, or new auth requests
  5. Cross-tab auth sync — BroadcastChannel synchronizes auth updates across browser tabs
  6. Password input UI — Add password/auth-id input field to ViewBuiltinClientAuthNotice for manual entry

Implementation details

  • human-id library added as inlined dependency for smaller bundle size
  • auth-state.ts module manages pending auth state, temporary IDs, and abort controller
  • Server's /auth-verify endpoint consumes temp IDs and resolves pending auth requests
  • Client-side RPC listener watches for BroadcastChannel auth updates and reloads on change
  • All tests pass (203 tests), build succeeds, and code is fully typed

Linked Issues

Closes auth UX improvements

Additional context

This enables three flexible auth workflows:

  1. Terminal prompt (existing) — now with visual auth URL
  2. Password-based auth (new) — for configured passwords
  3. URL-based auth (new) — one-click authorization from terminal link

Add human-readable auth IDs, configurable auth passwords, and an auth URL endpoint:

- Replace random nanoid with human-id (e.g. apple-banana-something-words)
- Add clientAuthPasswords config for pre-approved auth credentials
- Server generates temporary auth IDs for clickable auth URLs (/.devtools/auth?id=xxx)
- Terminal prompt shows auth URL and aborts on timeout (60s), URL usage, or new auth request
- Add BroadcastChannel to sync auth updates across browser tabs
- Add password input UI to ViewBuiltinClientAuthNotice for manual auth entry
- Add auth-state.ts module to manage pending auth state and temp ID consumption

All tests pass, build succeeds, and the feature is fully functional.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 18, 2026

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@229

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@229

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@229

@vitejs/devtools-rpc

npm i https://pkg.pr.new/@vitejs/devtools-rpc@229

@vitejs/devtools-self-inspect

npm i https://pkg.pr.new/@vitejs/devtools-self-inspect@229

commit: 711dfad

Add an "Auth Tokens" tab to the self-inspect debug panel that lists all
trusted clients with their auth ID, user agent, origin, and trust date.
Each token can be revoked individually.

- Add get-auth-tokens and revoke-auth-token RPC functions
- Export getInternalContext from @vitejs/devtools for cross-package access
- Add AuthTokensList component and auth page to self-inspect UI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antfu antfu changed the title feat: add human-readable auth IDs and multiple auth modes feat: add multiple auth modes Mar 19, 2026
antfu and others added 15 commits March 19, 2026 10:16
- Unify wording: clientAuthPasswords → clientAuthTokens, "password" → "token" in UI
- Add revokeAuthToken() utility that removes token from storage and notifies
  all connected clients using that token via auth:revoked broadcast event
- One token can be used by multiple clients; revoking disconnects all of them
- Client-side handler in rpc-ws.ts listens for auth:revoked and shows auth notice
- Self-inspect revoke RPC now uses the shared revokeAuthToken utility

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
/internal export

- Attach revokeAuthToken as a method on DevToolsInternalContext instead of
  a standalone exported function
- Create @vitejs/devtools/internal sub-export for getInternalContext
- Remove getInternalContext and revokeAuthToken from main entry point
- Add alias and tsconfig path for @vitejs/devtools/internal
- Update self-inspect to import from @vitejs/devtools/internal

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- When auth is revoked, close the current tab and panel in embedded mode
- Force dock mode to 'float' when unauthorized (regardless of settings)
- Standalone mode also clears selected entry on revocation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When unauthorized, DockEmbedded now renders in float mode by checking
isRpcTrusted rather than modifying panel.store.mode. This preserves the
user's mode preference while ensuring the unauthorized UI always shows
in float mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Unify all auth terminology to use "authToken" consistently:
- `authId` → `authToken` in interfaces, variables, and parameters
- `clientAuthId` → `clientAuthToken` in session meta
- `CONNECTION_AUTH_ID_KEY` → `CONNECTION_AUTH_TOKEN_KEY`
- `__VITE_DEVTOOLS_CONNECTION_AUTH_ID__` → `__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__`
- `getTempAuthId` → `getTempAuthToken`, `refreshTempAuthId` → `refreshTempAuthToken`
- `consumeTempAuthId` → `consumeTempAuthToken`
- Updated export snapshot for new human-id util

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `requestTrustWithToken(token)` to DevToolsRpcClient interface that
re-requests trust over the existing WS connection with a new token,
avoiding page reload that would lose user app state.

- BroadcastChannel auth-update handler now calls requestTrustWithToken
- ViewBuiltinClientAuthNotice submit calls context.rpc.requestTrustWithToken
- Token is persisted to localStorage/globalThis for future reconnections
- Static RPC mode provides no-op implementation (always trusted)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
clientAuthTokens from config were being stored in trusted storage on
auto-approve, which meant revoking them from self-inspect had no effect
since the next auth request would re-match the config and re-store.

Now config-based tokens only grant session-level trust (in-memory meta)
without persisting to storage. Only terminal-approved and temp-token
approved auth tokens are persisted.

Also use delete instead of = undefined for immer draft cleanup on revoke.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antfu antfu merged commit 6f0f194 into main Mar 19, 2026
8 checks passed
@antfu antfu deleted the antfu/human-readable-auth branch March 19, 2026 09:02
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