@@ -3,12 +3,12 @@ import process from 'node:process'
33import * as p from '@clack/prompts'
44import { defineRpcFunction } from '@vitejs/devtools-kit'
55import c from 'ansis'
6- import { abortPendingAuth , getTempAuthId , refreshTempAuthId , setPendingAuth } from '../../auth-state'
6+ import { abortPendingAuth , getTempAuthToken , refreshTempAuthToken , setPendingAuth } from '../../auth-state'
77import { MARK_INFO } from '../../constants'
88import { getInternalContext } from '../../context-internal'
99
1010export 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 ( ( ) => {
0 commit comments