11/* eslint-disable no-console */
2+ import process from 'node:process'
23import * as p from '@clack/prompts'
34import { defineRpcFunction } from '@vitejs/devtools-kit'
45import c from 'ansis'
5- import { abortPendingAuth , refreshTempAuthId , setPendingAuth } from '../../auth-state'
6+ import { abortPendingAuth , getTempAuthId , refreshTempAuthId , setPendingAuth } from '../../auth-state'
67import { MARK_INFO } from '../../constants'
78import { 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