Skip to content

Commit eeb9483

Browse files
antfuclaude
andcommitted
refactor: rename authId to authToken across entire codebase
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>
1 parent f85bfcf commit eeb9483

File tree

15 files changed

+88
-86
lines changed

15 files changed

+88
-86
lines changed

packages/core/src/client/webcomponents/components/views-builtin/ViewBuiltinClientAuthNotice.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function submitToken() {
1313
const value = tokenInput.value.trim()
1414
if (!value)
1515
return
16-
localStorage.setItem('__VITE_DEVTOOLS_CONNECTION_AUTH_ID__', value)
16+
localStorage.setItem('__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__', value)
1717
window.location.reload()
1818
}
1919
</script>

packages/core/src/node/auth-revoke.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export async function revokeAuthToken(
2424
// Collect affected session IDs before modifying meta
2525
const affectedSessionIds = new Set<string>()
2626
for (const client of rpcHost._rpcGroup.clients) {
27-
if (client.$meta.clientAuthId === token) {
27+
if (client.$meta.clientAuthToken === token) {
2828
affectedSessionIds.add(client.$meta.id)
2929
client.$meta.isTrusted = false
30-
client.$meta.clientAuthId = undefined!
30+
client.$meta.clientAuthToken = undefined!
3131
}
3232
}
3333

packages/core/src/node/auth-state.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { InternalAnonymousAuthStorage } from './context-internal'
44
import { humanId } from '@vitejs/devtools-kit/utils/human-id'
55

66
export interface PendingAuthRequest {
7-
clientAuthId: string
7+
clientAuthToken: string
88
session: DevToolsNodeRpcSession
99
ua: string
1010
origin: string
@@ -14,19 +14,19 @@ export interface PendingAuthRequest {
1414
}
1515

1616
let pendingAuth: PendingAuthRequest | null = null
17-
let tempAuthId: string = generateTempId()
17+
let tempAuthToken: string = generateTempId()
1818

1919
function generateTempId(): string {
2020
return humanId({ separator: '-', capitalize: false })
2121
}
2222

23-
export function getTempAuthId(): string {
24-
return tempAuthId
23+
export function getTempAuthToken(): string {
24+
return tempAuthToken
2525
}
2626

27-
export function refreshTempAuthId(): string {
28-
tempAuthId = generateTempId()
29-
return tempAuthId
27+
export function refreshTempAuthToken(): string {
28+
tempAuthToken = generateTempId()
29+
return tempAuthToken
3030
}
3131

3232
export function getPendingAuth(): PendingAuthRequest | null {
@@ -50,28 +50,28 @@ export function abortPendingAuth(): void {
5050

5151
/**
5252
* Consume the temp auth ID: verify it matches, trust the pending client, and clean up.
53-
* Returns the client's authId if successful, null otherwise.
53+
* Returns the client's authToken if successful, null otherwise.
5454
*/
55-
export function consumeTempAuthId(
55+
export function consumeTempAuthToken(
5656
id: string,
5757
storage: SharedState<InternalAnonymousAuthStorage>,
5858
): string | null {
59-
if (id !== tempAuthId || !pendingAuth) {
59+
if (id !== tempAuthToken || !pendingAuth) {
6060
return null
6161
}
6262

63-
const { clientAuthId, session, ua, origin, resolve } = pendingAuth
63+
const { clientAuthToken, session, ua, origin, resolve } = pendingAuth
6464

6565
// Trust the pending client
6666
storage.mutate((state) => {
67-
state.trusted[clientAuthId] = {
68-
authId: clientAuthId,
67+
state.trusted[clientAuthToken] = {
68+
authToken: clientAuthToken,
6969
ua,
7070
origin,
7171
timestamp: Date.now(),
7272
}
7373
})
74-
session.meta.clientAuthId = clientAuthId
74+
session.meta.clientAuthToken = clientAuthToken
7575
session.meta.isTrusted = true
7676

7777
// Resolve the pending auth RPC call
@@ -81,7 +81,7 @@ export function consumeTempAuthId(
8181
abortPendingAuth()
8282

8383
// Generate a new temp ID for next use
84-
refreshTempAuthId()
84+
refreshTempAuthToken()
8585

86-
return clientAuthId
86+
return clientAuthToken
8787
}

packages/core/src/node/context-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createStorage } from './storage'
77

88
export interface InternalAnonymousAuthStorage {
99
trusted: Record<string, {
10-
authId: string
10+
authToken: string
1111
ua: string
1212
origin: string
1313
timestamp: number

packages/core/src/node/rpc/anonymous/auth.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import process from 'node:process'
33
import * as p from '@clack/prompts'
44
import { defineRpcFunction } from '@vitejs/devtools-kit'
55
import c from 'ansis'
6-
import { abortPendingAuth, getTempAuthId, refreshTempAuthId, setPendingAuth } from '../../auth-state'
6+
import { abortPendingAuth, getTempAuthToken, refreshTempAuthToken, setPendingAuth } from '../../auth-state'
77
import { MARK_INFO } from '../../constants'
88
import { getInternalContext } from '../../context-internal'
99

1010
export interface DevToolsAuthInput {
11-
authId: string
11+
authToken: string
1212
ua: string
1313
origin: string
1414
}
@@ -31,29 +31,29 @@ export const anonymousAuth = defineRpcFunction({
3131
if (!session)
3232
throw new Error('Failed to retrieve the current RPC session')
3333

34-
if (session.meta.isTrusted || storage.value().trusted[query.authId]) {
35-
console.log('trusted', { isTrusted: session.meta.isTrusted, trusted: storage.value().trusted[query.authId] })
36-
session.meta.clientAuthId = query.authId
34+
if (session.meta.isTrusted || storage.value().trusted[query.authToken]) {
35+
console.log('trusted', { isTrusted: session.meta.isTrusted, trusted: storage.value().trusted[query.authToken] })
36+
session.meta.clientAuthToken = query.authToken
3737
session.meta.isTrusted = true
3838
return {
3939
isTrusted: true,
4040
}
4141
}
4242

43-
// Auto-approve if authId matches a configured auth token or the temp auth ID
43+
// Auto-approve if authToken matches a configured auth token or the temp auth ID
4444
const tokens = (context.viteConfig.devtools?.config as any)?.clientAuthTokens as string[] ?? []
45-
if (tokens.includes(query.authId) || query.authId === getTempAuthId()) {
45+
if (tokens.includes(query.authToken) || query.authToken === getTempAuthToken()) {
4646
storage.mutate((state) => {
47-
state.trusted[query.authId] = {
48-
authId: query.authId,
47+
state.trusted[query.authToken] = {
48+
authToken: query.authToken,
4949
ua: query.ua,
5050
origin: query.origin,
5151
timestamp: Date.now(),
5252
}
5353
})
54-
session.meta.clientAuthId = query.authId
54+
session.meta.clientAuthToken = query.authToken
5555
session.meta.isTrusted = true
56-
refreshTempAuthId()
56+
refreshTempAuthToken()
5757
return {
5858
isTrusted: true,
5959
}
@@ -63,7 +63,7 @@ export const anonymousAuth = defineRpcFunction({
6363
abortPendingAuth()
6464

6565
// Generate a fresh temp ID for the auth URL
66-
const tempId = getTempAuthId()
66+
const tempId = getTempAuthToken()
6767

6868
// Derive the server URL for the auth link
6969
const serverUrl = context.viteServer?.resolvedUrls?.local?.[0]?.replace(/\/$/, '')
@@ -75,7 +75,7 @@ export const anonymousAuth = defineRpcFunction({
7575
'',
7676
`User Agent : ${c.yellow(c.bold(query.ua || 'Unknown'))}`,
7777
`Origin : ${c.yellow(c.bold(query.origin || 'Unknown'))}`,
78-
`Client Token : ${c.green(c.bold(query.authId))}`,
78+
`Client Token : ${c.green(c.bold(query.authToken))}`,
7979
'',
8080
`Manual Auth URL : ${c.cyan(c.underline(authUrl))}`,
8181
`Manual Auth Token : ${c.cyan(c.bold(tempId))}`,
@@ -103,13 +103,13 @@ export const anonymousAuth = defineRpcFunction({
103103
const timeout = setTimeout(() => {
104104
abortController.abort()
105105
setPendingAuth(null)
106-
console.log(c.yellow`${MARK_INFO} Auth request timed out for ${c.bold(query.authId)}`)
106+
console.log(c.yellow`${MARK_INFO} Auth request timed out for ${c.bold(query.authToken)}`)
107107
resolve({ isTrusted: false })
108108
}, AUTH_TIMEOUT_MS)
109109

110110
// Register as pending auth so auth-verify endpoint can resolve it
111111
setPendingAuth({
112-
clientAuthId: query.authId,
112+
clientAuthToken: query.authToken,
113113
session,
114114
ua: query.ua,
115115
origin: query.origin,
@@ -120,7 +120,7 @@ export const anonymousAuth = defineRpcFunction({
120120

121121
// Show terminal confirm prompt with abort signal
122122
p.confirm({
123-
message: c.bold(`Do you trust this client (${c.green(c.bold(query.authId))})?`),
123+
message: c.bold(`Do you trust this client (${c.green(c.bold(query.authToken))})?`),
124124
initialValue: false,
125125
signal: abortController.signal,
126126
}).then((answer) => {
@@ -135,21 +135,21 @@ export const anonymousAuth = defineRpcFunction({
135135

136136
if (answer) {
137137
storage.mutate((state) => {
138-
state.trusted[query.authId] = {
139-
authId: query.authId,
138+
state.trusted[query.authToken] = {
139+
authToken: query.authToken,
140140
ua: query.ua,
141141
origin: query.origin,
142142
timestamp: Date.now(),
143143
}
144144
})
145-
session.meta.clientAuthId = query.authId
145+
session.meta.clientAuthToken = query.authToken
146146
session.meta.isTrusted = true
147147

148-
p.outro(c.green(c.bold(`You have granted permissions to ${c.bold(query.authId)}`)))
148+
p.outro(c.green(c.bold(`You have granted permissions to ${c.bold(query.authToken)}`)))
149149
resolve({ isTrusted: true })
150150
}
151151
else {
152-
p.outro(c.red(c.bold(`You have denied permissions to ${c.bold(query.authId)}`)))
152+
p.outro(c.red(c.bold(`You have denied permissions to ${c.bold(query.authToken)}`)))
153153
resolve({ isTrusted: false })
154154
}
155155
}).catch(() => {

packages/core/src/node/server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DEVTOOLS_CONNECTION_META_FILENAME } from '@vitejs/devtools-kit/constant
33
import { createApp, eventHandler, fromNodeMiddleware, getQuery, toNodeListener } from 'h3'
44
import sirv from 'sirv'
55
import { dirClientStandalone } from '../dirs'
6-
import { consumeTempAuthId } from './auth-state'
6+
import { consumeTempAuthToken } from './auth-state'
77
import { getInternalContext } from './context-internal'
88
import { createWsServer } from './ws'
99

@@ -27,20 +27,20 @@ function generateAuthPageHtml(): string {
2727
const el = document.getElementById('message')
2828
2929
if (!id) {
30-
el.textContent = '\\u26a0\\ufe0f No auth ID found. Please check your URL.'
30+
el.textContent = '\\u26a0\\ufe0f No auth token found. Please check your URL.'
3131
el.style.color = '#df513f'
3232
} else {
3333
fetch(location.pathname.replace(/\\/$/, '') + '-verify?id=' + encodeURIComponent(id))
3434
.then(async (r) => {
3535
if (r.status !== 200) throw new Error(await r.text())
3636
const data = await r.json()
37-
const authId = data.authId
37+
const authToken = data.authToken
3838
39-
localStorage.setItem('__VITE_DEVTOOLS_CONNECTION_AUTH_ID__', authId)
39+
localStorage.setItem('__VITE_DEVTOOLS_CONNECTION_AUTH_TOKEN__', authToken)
4040
4141
try {
4242
const bc = new BroadcastChannel('vite-devtools-auth')
43-
bc.postMessage({ type: 'auth-update', authId: authId })
43+
bc.postMessage({ type: 'auth-update', authToken: authToken })
4444
} catch {}
4545
4646
el.textContent = '\\u2705 Authorized! You can close this window now.'
@@ -74,14 +74,14 @@ export async function createDevToolsMiddleware(options: CreateWsServerOptions) {
7474
return event.node.res.end('Missing id parameter')
7575
}
7676

77-
const clientAuthId = consumeTempAuthId(id, contextInternal.storage.auth)
78-
if (!clientAuthId) {
77+
const clientAuthToken = consumeTempAuthToken(id, contextInternal.storage.auth)
78+
if (!clientAuthToken) {
7979
event.node.res.statusCode = 403
80-
return event.node.res.end('Invalid or expired auth ID')
80+
return event.node.res.end('Invalid or expired auth token')
8181
}
8282

8383
event.node.res.setHeader('Content-Type', 'application/json')
84-
return event.node.res.end(JSON.stringify({ authId: clientAuthId }))
84+
return event.node.res.end(JSON.stringify({ authToken: clientAuthToken }))
8585
}))
8686

8787
h3.use('/auth', eventHandler((event) => {

packages/core/src/node/ws.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ export async function createWsServer(options: CreateWsServerOptions) {
5252
}
5353
else if (authToken && contextInternal.storage.auth.value().trusted[authToken]) {
5454
meta.isTrusted = true
55-
meta.clientAuthId = authToken
55+
meta.clientAuthToken = authToken
5656
}
5757
else if (authToken && ((context.viteConfig.devtools?.config as any)?.clientAuthTokens ?? []).includes(authToken)) {
5858
meta.isTrusted = true
59-
meta.clientAuthId = authToken
59+
meta.clientAuthToken = authToken
6060
}
6161

6262
wsClients.add(ws)
6363
const color = meta.isTrusted ? c.green : c.yellow
64-
console.log(color`${MARK_INFO} Websocket client connected. [${meta.id}] [${meta.clientAuthId}] (${meta.isTrusted ? 'trusted' : 'untrusted'})`)
64+
console.log(color`${MARK_INFO} Websocket client connected. [${meta.id}] [${meta.clientAuthToken}] (${meta.isTrusted ? 'trusted' : 'untrusted'})`)
6565
},
6666
onDisconnected: (ws, meta) => {
6767
wsClients.delete(ws)

packages/kit/src/client/rpc-ws.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { parseUA } from 'ua-parser-modern'
77
import { promiseWithResolver } from '../utils/promise'
88

99
export interface CreateWsRpcClientModeOptions {
10-
authId: string
10+
authToken: string
1111
connectionMeta: ConnectionMeta
1212
events: EventEmitter<RpcClientEvents>
1313
clientRpc: DevToolsClientRpcHost
@@ -25,7 +25,7 @@ export function createWsRpcClientMode(
2525
options: CreateWsRpcClientModeOptions,
2626
): DevToolsRpcClientMode {
2727
const {
28-
authId,
28+
authToken,
2929
connectionMeta,
3030
events,
3131
clientRpc,
@@ -44,7 +44,7 @@ export function createWsRpcClientMode(
4444
{
4545
preset: createWsRpcPreset({
4646
url,
47-
authId,
47+
authToken,
4848
...wsOptions,
4949
}),
5050
rpcOptions,
@@ -76,7 +76,7 @@ export function createWsRpcClientMode(
7676
].filter(i => i).join(' ')
7777

7878
const result = await serverRpc.$call('vite:anonymous:auth', {
79-
authId,
79+
authToken,
8080
ua,
8181
origin: location.origin,
8282
})

0 commit comments

Comments
 (0)