@@ -60,27 +60,8 @@ export class LocalConnection {
6060 options . user = creds [ 0 ] ;
6161 options . password = creds [ 1 ] ;
6262 }
63- this . connLabel = connLabel ;
64-
65- if ( ext . customAuthApi ) {
66- const { kdb } = ext . customAuthApi . auth ( {
67- label : connLabel ,
68- kdb : {
69- host : options . host ,
70- port : options . port ,
71- user : options . user ,
72- password : options . password ,
73- unixSocket : options . unixSocket ,
74- socketTimeout : options . socketTimeout ,
75- socketNoDelay : options . socketNoDelay ,
76- } ,
77- } ) ;
78-
79- if ( kdb ) {
80- updateOptions ( options , kdb ) ;
81- }
82- }
8363
64+ this . connLabel = connLabel ;
8465 this . options = options ;
8566 this . connected = false ;
8667 }
@@ -92,7 +73,9 @@ export class LocalConnection {
9273 public async connect (
9374 callback : nodeq . AsyncValueCallback < LocalConnection > ,
9475 ) : Promise < void > {
95- nodeq . connect ( this . options , ( err , conn ) => {
76+ const options = await this . getCustomAuthOptions ( ) ;
77+
78+ nodeq . connect ( options , ( err , conn ) => {
9679 if ( err || ! conn ) {
9780 ext . serverProvider . reload ( ) ;
9881
@@ -386,22 +369,25 @@ export class LocalConnection {
386369 this . update ( ) ;
387370 callback ( err , this ) ;
388371 }
389- }
390372
391- function updateOptions ( options : any , kdb : any ) : void {
392- const keys = [
393- "host" ,
394- "port" ,
395- "user" ,
396- "password" ,
397- "unixSocket" ,
398- "socketTimeout" ,
399- "socketNoDelay" ,
400- ] ;
401-
402- keys . forEach ( ( key ) => {
403- if ( kdb [ key ] !== undefined ) {
404- options [ key ] = kdb [ key ] ;
373+ async getCustomAuthOptions ( ) : Promise < nodeq . ConnectionParameters > {
374+ if ( ext . customAuth ) {
375+ const { kdb } = await ext . customAuth . auth ( {
376+ label : this . connLabel ,
377+ kdb : {
378+ host : this . options . host ,
379+ port : this . options . port ,
380+ user : this . options . user ,
381+ password : this . options . password ,
382+ unixSocket : this . options . unixSocket ,
383+ socketTimeout : this . options . socketTimeout ,
384+ socketNoDelay : this . options . socketNoDelay ,
385+ } ,
386+ } ) ;
387+ if ( kdb ) {
388+ return { ...this . options , ...kdb } ;
389+ }
405390 }
406- } ) ;
391+ return this . options ;
392+ }
407393}
0 commit comments