humanmade / repress

Connect your Redux store to the WordPress REST API.
Other
83 stars 11 forks source link

Don’t overwrite fetchOptions with local options #37

Closed darylldoyle closed 5 years ago

darylldoyle commented 5 years ago

When using createSingle() or updateSingle() the header options set in the handler on initialisation are overwritten by the options passed to this.fetch()

const options = {
    method:  'POST',
    headers: { 'Content-Type': 'application/json' },
    body:    JSON.stringify( data ),
};
return this.fetch( this.url, { context: 'edit' }, options )

For this reason, it's not possible to use repress to create items that need auth by using an Authorization header (JWT for example).

I'd suggest switching the order of the options being spread in the fetch() method so that the headers set on the handler take precedent.

rmccue commented 5 years ago

I'd rather solve it with deep merging per #29. I think I actually have a patch for this somewhere...

rmccue commented 5 years ago

Found the patch, so closing this one. Thanks for the time though!