nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

Globally set options.Credentials #92

Closed darthf1 closed 4 years ago

darthf1 commented 4 years ago

Hi. Is there a way to globally set options.credentials = 'include'? I tried with the onRequest hook but then I get a TS error.

import { Plugin } from '@nuxt/types'

const httpPlugin: Plugin = ({ $http }) => {
  $http.onRequest((config) => {
    config.credentials = 'include'
  })
}

export default httpPlugin
`TS2540: Cannot assign to 'credentials' because it is a read-only property.`

If I add a // @ts-ignore on this error, the request won't be made. If I remove the code all together, the request is made.

Is there another way to set this globally instead of every request?

ghost commented 4 years ago

This issue as been imported as question since it does not respect http issue template. Only bug reports and feature requests stays open to reduce maintainers workload. If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically. Your question is available at https://cmty.app/nuxt/http/issues/c23.

wildan2711 commented 4 years ago

Did you find solution? I need this too.

darthf1 commented 4 years ago

No solution unfortunately

desislavsd commented 4 years ago

You may create a plugin and add the following:

export default ( { $http } ) => {

    $http._defaults.credentials = 'include'; 
}
notiv-nt commented 3 years ago

+1 for the comment above, and don't forget to add plugin to the nuxt.config.js