nuxt-community / laravel-echo-module

Laravel Echo for Nuxt 2
MIT License
86 stars 31 forks source link

Make this package use my Axios instance #15

Open Zhythero opened 4 years ago

Zhythero commented 4 years ago

Hi,

So I have this nuxt module installed along with nuxt's axios module. My axios instance is currently having a X-XSRF-TOKEN header configured inside it (because Laravel Sanctum) and I need this module to use the axios instance so that I can authenticate my SPA with Laravel's Broadcasting.

ricardogobbosouza commented 4 years ago

Hi @Zhythero

I will make headers accept a function. In the meantime you can create a plugin

// nuxt.config.js
export default {
  buildModules: [
    '@nuxtjs/laravel-echo'
  ],
  echo: {
    plugins: ['~/plugins/echo.js']
  }
}
// plugins/echo.js
export default function ({ $echo, app }) {
  $echo.options.auth.headers['X-XSRF-TOKEN'] = 'TOKEN'
  $echo.connect()
}
ricardogobbosouza commented 3 years ago

Hi @Zhythero Try this version: 2.0.0-alpha.1 Added support for Laravel Sanctum with auth-module v5 https://github.com/nuxt-community/laravel-echo-module/blob/main/src/runtime/echo.ts#L37

ricardogobbosouza commented 3 years ago

47