@@ -115,15 +115,24 @@ export const dialDirect = async (
115
115
116
116
// Client already has access token with no external auth, skip Authenticate process.
117
117
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
+ )
120
126
) {
121
127
const headers = new Headers ( opts . extraHeaders ) ;
122
128
headers . set ( 'authorization' , `Bearer ${ opts . accessToken } ` ) ;
123
129
return new AuthenticatedTransport ( transportOpts , createTransport , headers ) ;
124
130
}
125
131
126
- if ( ! opts || ( ! opts . credentials && ! opts . accessToken ) ) {
132
+ if (
133
+ opts === undefined ||
134
+ ( opts . credentials === undefined && opts . accessToken === undefined )
135
+ ) {
127
136
return createTransport ( transportOpts ) ;
128
137
}
129
138
@@ -146,7 +155,7 @@ const makeAuthenticatedTransport = async (
146
155
const authHeaders = new Headers ( opts . extraHeaders ) ;
147
156
148
157
let accessToken ;
149
- if ( ! opts . accessToken || opts . accessToken === '' ) {
158
+ if ( opts . accessToken === undefined || opts . accessToken === '' ) {
150
159
const request = new AuthenticateRequest ( {
151
160
entity :
152
161
isCredential ( opts . credentials ) && opts . credentials . authEntity
@@ -169,7 +178,12 @@ const makeAuthenticatedTransport = async (
169
178
accessToken = opts . accessToken ;
170
179
}
171
180
172
- if ( opts . externalAuthAddress && opts . externalAuthToEntity ) {
181
+ if (
182
+ opts . externalAuthAddress !== undefined &&
183
+ opts . externalAuthAddress !== '' &&
184
+ opts . externalAuthToEntity !== undefined &&
185
+ opts . externalAuthToEntity !== ''
186
+ ) {
173
187
const extAuthHeaders = new Headers ( ) ;
174
188
extAuthHeaders . set ( 'authorization' , `Bearer ${ accessToken } ` ) ;
175
189
@@ -385,7 +399,7 @@ export const dialWebRTC = async (
385
399
) ;
386
400
try {
387
401
// set timeout for dial attempt if a timeout is specified
388
- if ( dialOpts ?. dialTimeout ) {
402
+ if ( dialOpts ?. dialTimeout !== undefined ) {
389
403
setTimeout ( ( ) => {
390
404
if ( ! successful ) {
391
405
exchange . terminate ( ) ;
@@ -395,10 +409,13 @@ export const dialWebRTC = async (
395
409
396
410
const cc = await exchange . doExchange ( ) ;
397
411
398
- if ( dialOpts ?. externalAuthAddress ) {
412
+ if (
413
+ dialOpts ?. externalAuthAddress !== undefined &&
414
+ dialOpts . externalAuthAddress !== ''
415
+ ) {
399
416
// TODO(GOUT-11): prepare AuthenticateTo here for client channel.
400
417
// eslint-disable-next-line sonarjs/no-duplicated-branches
401
- } else if ( dialOpts ?. credentials ?. type ) {
418
+ } else if ( dialOpts ?. credentials ?. type !== undefined ) {
402
419
// TODO(GOUT-11): prepare Authenticate here for client channel
403
420
}
404
421
@@ -477,14 +494,16 @@ const processSignalingExchangeOpts = (
477
494
if ( dialOpts ) {
478
495
optsCopy = { ...dialOpts } as DialOptions ;
479
496
480
- if ( ! dialOpts . accessToken ) {
497
+ if ( dialOpts . accessToken === undefined ) {
481
498
if (
482
499
isCredential ( optsCopy . credentials ) &&
483
500
! optsCopy . credentials . authEntity
484
501
) {
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 , '' ) ;
488
507
}
489
508
optsCopy . credentials = dialOpts . webrtcOptions ?. signalingCredentials ;
490
509
optsCopy . accessToken = dialOpts . webrtcOptions ?. signalingAccessToken ;
@@ -504,18 +523,18 @@ const validateDialOptions = (opts?: DialOptions) => {
504
523
return ;
505
524
}
506
525
507
- if ( opts . accessToken && opts . accessToken . length > 0 ) {
526
+ if ( opts . accessToken !== undefined && opts . accessToken . length > 0 ) {
508
527
if ( opts . credentials ) {
509
528
throw new Error ( 'cannot set credentials with accessToken' ) ;
510
529
}
511
530
512
- if ( opts . webrtcOptions ) {
513
- if ( opts . webrtcOptions . signalingAccessToken ) {
531
+ if ( opts . webrtcOptions !== undefined ) {
532
+ if ( opts . webrtcOptions . signalingAccessToken !== undefined ) {
514
533
throw new Error (
515
534
'cannot set webrtcOptions.signalingAccessToken with accessToken'
516
535
) ;
517
536
}
518
- if ( opts . webrtcOptions . signalingCredentials ) {
537
+ if ( opts . webrtcOptions . signalingCredentials !== undefined ) {
519
538
throw new Error (
520
539
'cannot set webrtcOptions.signalingCredentials with accessToken'
521
540
) ;
@@ -524,9 +543,9 @@ const validateDialOptions = (opts?: DialOptions) => {
524
543
}
525
544
526
545
if (
527
- opts . webrtcOptions ?. signalingAccessToken &&
546
+ opts . webrtcOptions ?. signalingAccessToken !== undefined &&
528
547
opts . webrtcOptions . signalingAccessToken . length > 0 &&
529
- opts . webrtcOptions . signalingCredentials
548
+ opts . webrtcOptions . signalingCredentials !== undefined
530
549
) {
531
550
throw new Error (
532
551
'cannot set webrtcOptions.signalingCredentials with webrtcOptions.signalingAccessToken'
0 commit comments