devour-js / devour-client

Don't just consume your JSON API, Devour it...
https://www.npmjs.com/package/devour-client
ISC License
429 stars 89 forks source link

[Question] set withCredentials = true #158

Closed luizcastrolfc closed 6 years ago

luizcastrolfc commented 6 years ago

Is there a way to set withCredentials = true? axios example: const api = axios.create({ withCredentials: true, ... })

tomers commented 6 years ago

I think a middleware could do the trick:

let requestWithCredentialsMiddleware = {
  name: 'with-credentials',
  req: (payload) => {
    payload.withCredentials = true
    return payload
  }
}

And use it here:

jsonApiInstance.insertMiddlewareBefore('axios-request', requestWithCredentialsMiddleware)

Or maybe setting defaults would be a simpler solution:

jsonApiInstance.axios.defaults.withCredentials = true

I haven't tried either of these. Please report your findings.

sk-pub commented 5 years ago

Just to report feedback. jsonApiInstance.axios.defaults.withCredentials = true works perfectly.