@@ -278,7 +278,7 @@ function openInBrowser(url: string): Promise<void> {
278278
279279export async function runConsoleLogin (
280280 consoleOrigin : string ,
281- opts ?: { needApiKey ?: boolean } ,
281+ opts ?: { needApiKey ?: boolean ; onApiKey ?: ( key : string ) => Promise < void > } ,
282282) : Promise < void > {
283283 const state = randomBytes ( 16 ) . toString ( "hex" ) ;
284284 const server = http . createServer ( async ( req , res ) => {
@@ -304,12 +304,15 @@ export async function runConsoleLogin(
304304
305305 if ( accessToken || apiKey ) {
306306 try {
307- const existing = readConfigFile ( ) as Record < string , unknown > ;
308- if ( accessToken ) existing . access_token = accessToken ;
309- if ( apiKey ) existing . api_key = apiKey ;
310- await writeConfigFile ( existing ) ;
311- if ( accessToken ) process . stderr . write ( `access_token saved to ${ getConfigPath ( ) } \n` ) ;
312- if ( apiKey ) process . stderr . write ( `api_key saved to ${ getConfigPath ( ) } \n` ) ;
307+ if ( accessToken ) {
308+ const existing = readConfigFile ( ) as Record < string , unknown > ;
309+ existing . access_token = accessToken ;
310+ await writeConfigFile ( existing ) ;
311+ process . stderr . write ( `access_token saved to ${ getConfigPath ( ) } \n` ) ;
312+ }
313+ if ( apiKey && opts ?. onApiKey ) {
314+ await opts . onApiKey ( apiKey ) ;
315+ }
313316 } catch {
314317 res . writeHead ( 500 , { "Content-Type" : "text/plain; charset=utf-8" } ) ;
315318 res . end ( "Failed to save credentials\n" ) ;
0 commit comments