@@ -17,22 +17,25 @@ module.exports = function listen(query, params, opts = {}) {
17
17
const options = defaults ( opts , defaultOptions )
18
18
const listenOpts = pick ( options , possibleOptions )
19
19
const qs = encodeQueryString ( { query, params, options : listenOpts } )
20
- const { url, token} = this . clientConfig
21
-
22
- const authHeaders = { }
23
- if ( token ) {
24
- authHeaders . Authorization = `Bearer ${ token } `
25
- }
20
+ const { url, token, withCredentials} = this . clientConfig
26
21
27
22
const uri = `${ url } ${ this . getDataUrl ( 'listen' , qs ) } `
28
23
const listenFor = options . events ? options . events : [ 'mutation' ]
29
24
const shouldEmitReconnect = listenFor . indexOf ( 'reconnect' ) !== - 1
30
25
26
+ const esOptions = { }
27
+ if ( token || withCredentials ) {
28
+ esOptions . withCredentials = true
29
+ }
30
+
31
+ if ( token ) {
32
+ esOptions . headers = {
33
+ Authorization : `Bearer ${ token } `
34
+ }
35
+ }
36
+
31
37
return new Observable ( observer => {
32
- const es = new EventSource ( uri , assign (
33
- { withCredentials : true } ,
34
- token ? { headers : authHeaders } : { }
35
- ) )
38
+ const es = new EventSource ( uri , esOptions )
36
39
37
40
es . addEventListener ( 'error' , onError , false )
38
41
es . addEventListener ( 'channelError' , onChannelError , false )
0 commit comments