401 (unauthorized) in Chrome, but not in IE

I recently switched from using jQuery to using isomorphic fetching using Redux. When working in IE, he manages to get a fine. However, when launched in Chrome, I get below.

Failed to load resource: the server responded with a status of 401 (Unauthorized) 

It might be worth noting that Windows authentication is included in the web api.

Here is the code that performs the selection:

 export const fetchSearchResults = (name) => { return (dispatch) => { dispatch(requestSearchResults(name)) return fetch(API URI HERE) .then(response => response.json()) .then(json => { console.log('Fetch: ' + json.message.features.length) dispatch(receiveSearchResults(json)) }) } } 
+8
javascript google-chrome fetch redux unauthorized
source share
1 answer

I assume that you have cookie based authentication on the server. In this case, it can be associated with the credentials key for fetch . The XHR requests used in jQuery always send your cookie, but using fetch , you must pass the credentials with

  • same-origin if you make a request to the same origin (domain)
  • include otherwise

Like this:

 ... fetch(API_URI_HERE, {credentials: 'same-origin'}) ... 

I assume it works in IE because fetch polyfill uses XHR requests under the hood.

+24
source share

All Articles