@@ -199,36 +199,35 @@ class Client extends EventEmitter {
199199 // TODO(bmc): deprecate pgpass "built in" integration since this.password can be a function
200200 // it can be supplied by the user if required - this is a breaking change!
201201 _checkPgPass ( cb ) {
202- return function ( msg ) {
203- if ( typeof this . password === 'function' ) {
204- this . _Promise
205- . resolve ( )
206- . then ( ( ) => this . password ( ) )
207- . then ( ( pass ) => {
208- if ( pass !== undefined ) {
209- if ( typeof pass !== 'string' ) {
210- con . emit ( 'error' , new TypeError ( 'Password must be a string' ) )
211- return
212- }
213- this . connectionParameters . password = this . password = pass
214- } else {
215- this . connectionParameters . password = this . password = null
202+ const con = this . connection
203+ if ( typeof this . password === 'function' ) {
204+ this . _Promise
205+ . resolve ( )
206+ . then ( ( ) => this . password ( ) )
207+ . then ( ( pass ) => {
208+ if ( pass !== undefined ) {
209+ if ( typeof pass !== 'string' ) {
210+ con . emit ( 'error' , new TypeError ( 'Password must be a string' ) )
211+ return
216212 }
217- cb ( msg )
218- } )
219- . catch ( ( err ) => {
220- con . emit ( 'error' , err )
221- } )
222- } else if ( this . password !== null ) {
223- cb ( msg )
224- } else {
225- pgPass ( this . connectionParameters , function ( pass ) {
226- if ( undefined !== pass ) {
227213 this . connectionParameters . password = this . password = pass
214+ } else {
215+ this . connectionParameters . password = this . password = null
228216 }
229- cb ( msg )
217+ cb ( )
230218 } )
231- }
219+ . catch ( ( err ) => {
220+ con . emit ( 'error' , err )
221+ } )
222+ } else if ( this . password !== null ) {
223+ cb ( )
224+ } else {
225+ pgPass ( this . connectionParameters , function ( pass ) {
226+ if ( undefined !== pass ) {
227+ this . connectionParameters . password = this . password = pass
228+ }
229+ cb ( )
230+ } )
232231 }
233232 }
234233
@@ -239,14 +238,14 @@ class Client extends EventEmitter {
239238 }
240239
241240 _handleAuthMD5Password ( msg ) {
242- this . _checkPgPass ( ( msg ) => {
241+ this . _checkPgPass ( ( ) => {
243242 const hashedPassword = utils . postgresMd5PasswordHash ( this . user , this . password , msg . salt )
244243 this . connection . password ( hashedPassword )
245244 } )
246245 }
247246
248- _handleAuthSASL ( msg ) {
249- this . _checkPgPass ( ( msg ) => {
247+ _handleAuthSASL ( ) {
248+ this . _checkPgPass ( ( ) => {
250249 this . saslSession = sasl . startSession ( msg . mechanisms )
251250 const con = this . connection
252251 con . sendSASLInitialResponseMessage ( saslSession . mechanism , saslSession . response )
0 commit comments