Procházet zdrojové kódy

Send cookies with fetch requests

The current default value for credentials is "same-origin", however some browsers implement an older version of the specification where the default was "omit".

See https://github.com/github/fetch for more information.
Geoff Appleford před 6 roky
rodič
revize
432a86d8a8

+ 4 - 1
packages/@uppy/companion-client/src/RequestClient.js

@@ -55,7 +55,8 @@ module.exports = class RequestClient {
   get (path) {
   get (path) {
     return fetch(this._getUrl(path), {
     return fetch(this._getUrl(path), {
       method: 'get',
       method: 'get',
-      headers: this.headers
+      headers: this.headers,
+      credentials: 'same-origin'
     })
     })
       // @todo validate response status before calling json
       // @todo validate response status before calling json
       .then(this.onReceiveResponse)
       .then(this.onReceiveResponse)
@@ -69,6 +70,7 @@ module.exports = class RequestClient {
     return fetch(this._getUrl(path), {
     return fetch(this._getUrl(path), {
       method: 'post',
       method: 'post',
       headers: this.headers,
       headers: this.headers,
+      credentials: 'same-origin',
       body: JSON.stringify(data)
       body: JSON.stringify(data)
     })
     })
       .then(this.onReceiveResponse)
       .then(this.onReceiveResponse)
@@ -87,6 +89,7 @@ module.exports = class RequestClient {
     return fetch(`${this.hostname}/${path}`, {
     return fetch(`${this.hostname}/${path}`, {
       method: 'delete',
       method: 'delete',
       headers: this.headers,
       headers: this.headers,
+      credentials: 'same-origin',
       body: data ? JSON.stringify(data) : null
       body: data ? JSON.stringify(data) : null
     })
     })
       .then(this.onReceiveResponse)
       .then(this.onReceiveResponse)