@@ -115,15 +115,24 @@ export const dialDirect = async (
115115
116116 // Client already has access token with no external auth, skip Authenticate process.
117117 if (
118- opts ?. accessToken &&
119- ! ( opts . externalAuthAddress && opts . externalAuthToEntity )
118+ opts ?. accessToken !== undefined &&
119+ opts . accessToken !== '' &&
120+ ! (
121+ opts . externalAuthAddress !== undefined &&
122+ opts . externalAuthAddress !== '' &&
123+ opts . externalAuthToEntity !== undefined &&
124+ opts . externalAuthToEntity !== ''
125+ )
120126 ) {
121127 const headers = new Headers ( opts . extraHeaders ) ;
122128 headers . set ( 'authorization' , `Bearer ${ opts . accessToken } ` ) ;
123129 return new AuthenticatedTransport ( transportOpts , createTransport , headers ) ;
124130 }
125131
126- if ( ! opts || ( ! opts . credentials && ! opts . accessToken ) ) {
132+ if (
133+ opts === undefined ||
134+ ( opts . credentials === undefined && opts . accessToken === undefined )
135+ ) {
127136 return createTransport ( transportOpts ) ;
128137 }
129138
@@ -146,7 +155,7 @@ const makeAuthenticatedTransport = async (
146155 const authHeaders = new Headers ( opts . extraHeaders ) ;
147156
148157 let accessToken ;
149- if ( ! opts . accessToken || opts . accessToken === '' ) {
158+ if ( opts . accessToken === undefined || opts . accessToken === '' ) {
150159 const request = new AuthenticateRequest ( {
151160 entity :
152161 isCredential ( opts . credentials ) && opts . credentials . authEntity
@@ -169,7 +178,12 @@ const makeAuthenticatedTransport = async (
169178 accessToken = opts . accessToken ;
170179 }
171180
172- if ( opts . externalAuthAddress && opts . externalAuthToEntity ) {
181+ if (
182+ opts . externalAuthAddress !== undefined &&
183+ opts . externalAuthAddress !== '' &&
184+ opts . externalAuthToEntity !== undefined &&
185+ opts . externalAuthToEntity !== ''
186+ ) {
173187 const extAuthHeaders = new Headers ( ) ;
174188 extAuthHeaders . set ( 'authorization' , `Bearer ${ accessToken } ` ) ;
175189
@@ -385,7 +399,7 @@ export const dialWebRTC = async (
385399 ) ;
386400 try {
387401 // set timeout for dial attempt if a timeout is specified
388- if ( dialOpts ?. dialTimeout ) {
402+ if ( dialOpts ?. dialTimeout !== undefined ) {
389403 setTimeout ( ( ) => {
390404 if ( ! successful ) {
391405 exchange . terminate ( ) ;
@@ -395,10 +409,13 @@ export const dialWebRTC = async (
395409
396410 const cc = await exchange . doExchange ( ) ;
397411
398- if ( dialOpts ?. externalAuthAddress ) {
412+ if (
413+ dialOpts ?. externalAuthAddress !== undefined &&
414+ dialOpts . externalAuthAddress !== ''
415+ ) {
399416 // TODO(GOUT-11): prepare AuthenticateTo here for client channel.
400417 // eslint-disable-next-line sonarjs/no-duplicated-branches
401- } else if ( dialOpts ?. credentials ?. type ) {
418+ } else if ( dialOpts ?. credentials ?. type !== undefined ) {
402419 // TODO(GOUT-11): prepare Authenticate here for client channel
403420 }
404421
@@ -477,14 +494,16 @@ const processSignalingExchangeOpts = (
477494 if ( dialOpts ) {
478495 optsCopy = { ...dialOpts } as DialOptions ;
479496
480- if ( ! dialOpts . accessToken ) {
497+ if ( dialOpts . accessToken === undefined ) {
481498 if (
482499 isCredential ( optsCopy . credentials ) &&
483500 ! optsCopy . credentials . authEntity
484501 ) {
485- optsCopy . credentials . authEntity = optsCopy . externalAuthAddress
486- ? optsCopy . externalAuthAddress . replace ( addressCleanupRegex , '' )
487- : signalingAddress . replace ( addressCleanupRegex , '' ) ;
502+ optsCopy . credentials . authEntity =
503+ optsCopy . externalAuthAddress !== undefined &&
504+ optsCopy . externalAuthAddress !== ''
505+ ? optsCopy . externalAuthAddress . replace ( addressCleanupRegex , '' )
506+ : signalingAddress . replace ( addressCleanupRegex , '' ) ;
488507 }
489508 optsCopy . credentials = dialOpts . webrtcOptions ?. signalingCredentials ;
490509 optsCopy . accessToken = dialOpts . webrtcOptions ?. signalingAccessToken ;
@@ -504,18 +523,18 @@ const validateDialOptions = (opts?: DialOptions) => {
504523 return ;
505524 }
506525
507- if ( opts . accessToken && opts . accessToken . length > 0 ) {
526+ if ( opts . accessToken !== undefined && opts . accessToken . length > 0 ) {
508527 if ( opts . credentials ) {
509528 throw new Error ( 'cannot set credentials with accessToken' ) ;
510529 }
511530
512- if ( opts . webrtcOptions ) {
513- if ( opts . webrtcOptions . signalingAccessToken ) {
531+ if ( opts . webrtcOptions !== undefined ) {
532+ if ( opts . webrtcOptions . signalingAccessToken !== undefined ) {
514533 throw new Error (
515534 'cannot set webrtcOptions.signalingAccessToken with accessToken'
516535 ) ;
517536 }
518- if ( opts . webrtcOptions . signalingCredentials ) {
537+ if ( opts . webrtcOptions . signalingCredentials !== undefined ) {
519538 throw new Error (
520539 'cannot set webrtcOptions.signalingCredentials with accessToken'
521540 ) ;
@@ -524,9 +543,9 @@ const validateDialOptions = (opts?: DialOptions) => {
524543 }
525544
526545 if (
527- opts . webrtcOptions ?. signalingAccessToken &&
546+ opts . webrtcOptions ?. signalingAccessToken !== undefined &&
528547 opts . webrtcOptions . signalingAccessToken . length > 0 &&
529- opts . webrtcOptions . signalingCredentials
548+ opts . webrtcOptions . signalingCredentials !== undefined
530549 ) {
531550 throw new Error (
532551 'cannot set webrtcOptions.signalingCredentials with webrtcOptions.signalingAccessToken'
0 commit comments