Skip to content

fix(devtools): require dev auth token for openInEditor and options RPC methods - #1039

Merged
antfu merged 3 commits into
v3from
fix/devtools-rpc-auth
Jul 24, 2026
Merged

fix(devtools): require dev auth token for openInEditor and options RPC methods#1039
antfu merged 3 commits into
v3from
fix/devtools-rpc-auth

Conversation

@antfubot

Copy link
Copy Markdown
Collaborator

Summary

A few mutating server RPC methods were not gated on the dev auth token, unlike the rest of the RPC surface. This aligns them with the existing convention so that every method that runs a command or writes to disk goes through ensureDevAuthToken.

Methods now token-gated:

  • openInEditor — opens a file in the user's editor
  • updateOptions — persists DevTools options to disk
  • clearOptions — resets persisted DevTools options

This matches how restartNuxt, storage writes, npm actions, terminals, etc. already work.

Changes

  • Server: openInEditor, updateOptions, clearOptions now take a token first argument and call ensureDevAuthToken(token) before doing any work. getOptions (read-only) is unchanged.
  • Types: updated the ServerFunctions signatures in @nuxt/devtools-kit.
  • Client: callers pass the token via ensureDevAuthToken(). The passive UI-options watcher only persists when the session is already authenticated (it never triggers an auth prompt from background writes), while the Settings page ensures auth on the first deliberate edit so changes still persist.
  • Tests: added a focused unit test asserting the three methods reject an invalid token and proceed with a valid one, plus a minimal vitest setup and test:unit wiring.

Notes

  • Behavior for authenticated sessions is unchanged; the auth token is remembered in localStorage and silently re-verified, so this is effectively a one-time prompt per browser.
  • disableAuthorization (e.g. sandboxed environments) continues to bypass the check as before.

This PR was created with the help of an agent.

…C methods

Gate the openInEditor, updateOptions and clearOptions RPC methods on the
dev auth token, consistent with the rest of the mutating RPC surface
(restartNuxt, storage writes, npm, terminals, ...). Update the client
callers to pass the token, keep the passive UI-options watcher silent when
unauthenticated, and add a focused unit test for the token checks.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploying nuxt-devtools with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8b84b29
Status: ✅  Deploy successful!
Preview URL: https://e49e8691.nuxt-devtools.pages.dev
Branch Preview URL: https://fix-devtools-rpc-auth.nuxt-devtools.pages.dev

View logs

The build task had no dependsOn, so with caching cold turbo could build
@nuxt/devtools before its workspace dependency @nuxt/devtools-kit was
built, intermittently failing with MODULE_NOT_FOUND. Add "^build" so
dependencies are built first.
nuxt.options and the ServerFunctions return type resolve to two different
NuxtOptions copies (@nuxt/schema vs nuxt/schema) that diverge on the unocss
augmentation, breaking vue-tsc. Cast to the declared return type, matching
the equivalent fix already on main.
@antfu
antfu merged commit a7b2718 into v3 Jul 24, 2026
6 checks passed
@antfu
antfu deleted the fix/devtools-rpc-auth branch July 24, 2026 04:57
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