Skip to content

Commit cb66bb9

Browse files
committed
feat: update temp auth
1 parent 4326290 commit cb66bb9

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
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
@@ -23,7 +23,7 @@ function submitToken() {
2323
<div class="max-w-150 flex flex-col items-center justify-center gap-2">
2424
<VitePlus class="w-20 h-20" />
2525
<h1 class="text-2xl font-bold text-violet mb2">
26-
Vite DevTools is Unauthorized
26+
Vite DevTools needs Authorization
2727
</h1>
2828
<p class="op75">
2929
Vite DevTools offers advanced features that can access your server, view your filesystem, and execute commands.

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable no-console */
2+
import process from 'node:process'
23
import * as p from '@clack/prompts'
34
import { defineRpcFunction } from '@vitejs/devtools-kit'
45
import c from 'ansis'
5-
import { abortPendingAuth, refreshTempAuthId, setPendingAuth } from '../../auth-state'
6+
import { abortPendingAuth, getTempAuthId, refreshTempAuthId, setPendingAuth } from '../../auth-state'
67
import { MARK_INFO } from '../../constants'
78
import { getInternalContext } from '../../context-internal'
89

@@ -38,9 +39,9 @@ export const anonymousAuth = defineRpcFunction({
3839
}
3940
}
4041

41-
// Auto-approve if authId matches a configured auth token
42+
// Auto-approve if authId matches a configured auth token or the temp auth ID
4243
const tokens = (context.viteConfig.devtools?.config as any)?.clientAuthTokens as string[] ?? []
43-
if (tokens.includes(query.authId)) {
44+
if (tokens.includes(query.authId) || query.authId === getTempAuthId()) {
4445
storage.mutate((state) => {
4546
state.trusted[query.authId] = {
4647
authId: query.authId,
@@ -51,6 +52,7 @@ export const anonymousAuth = defineRpcFunction({
5152
})
5253
session.meta.clientAuthId = query.authId
5354
session.meta.isTrusted = true
55+
refreshTempAuthId()
5456
return {
5557
isTrusted: true,
5658
}
@@ -60,7 +62,7 @@ export const anonymousAuth = defineRpcFunction({
6062
abortPendingAuth()
6163

6264
// Generate a fresh temp ID for the auth URL
63-
const tempId = refreshTempAuthId()
65+
const tempId = getTempAuthId()
6466

6567
// Derive the server URL for the auth link
6668
const serverUrl = context.viteServer?.resolvedUrls?.local?.[0]?.replace(/\/$/, '')
@@ -70,11 +72,12 @@ export const anonymousAuth = defineRpcFunction({
7072
const message = [
7173
`A browser is requesting permissions to connect to the Vite DevTools.`,
7274
'',
73-
`User Agent: ${c.yellow(c.bold(query.ua || 'Unknown'))}`,
74-
`Origin : ${c.cyan(c.bold(query.origin || 'Unknown'))}`,
75-
`Identifier: ${c.green(c.bold(query.authId))}`,
75+
`User Agent : ${c.yellow(c.bold(query.ua || 'Unknown'))}`,
76+
`Origin : ${c.yellow(c.bold(query.origin || 'Unknown'))}`,
77+
`Client Token : ${c.green(c.bold(query.authId))}`,
7678
'',
77-
`Auth URL : ${c.cyan(c.underline(authUrl))}`,
79+
`Auth URL : ${c.cyan(c.underline(authUrl))}`,
80+
`Temp Token : ${c.cyan(c.bold(tempId))}`,
7881
'',
7982
'This will allow the browser to interact with the server, make file changes and run commands.',
8083
c.red(c.bold('You should only trust your local development browsers.')),
@@ -85,6 +88,13 @@ export const anonymousAuth = defineRpcFunction({
8588
c.bold(c.yellow(' Vite DevTools Permission Request ')),
8689
)
8790

91+
// if non-TTY, skip the prompt
92+
if (!process.stdout.isTTY) {
93+
return {
94+
isTrusted: false,
95+
}
96+
}
97+
8898
// Set up abort controller for timeout and external cancellation
8999
const abortController = new AbortController()
90100

0 commit comments

Comments
 (0)