nuxt-community / laravel-echo-module

Laravel Echo for Nuxt 2
MIT License
85 stars 32 forks source link

Add support for authorizer #45

Open ricardogobbosouza opened 3 years ago

ricardogobbosouza commented 3 years ago

Hi @radudiaconu0, @farazappy Try this version: 2.0.0-alpha.1 Added optionsPath like https://github.com/nuxt-community/vuetify-module#optionspath

// app/laravel-echo/options.js

export default /* async */ function (ctx) {
  return {
    authorizer (channel, options) {
      return {
        authorize (socketId, callback) {
          ctx.app.$axios.post(options.authEndpoint, {
            socket_id: socketId,
            channel_name: channel.name
          })
            .then((response) => {
              callback(false, response.data)
            })
            .catch((error) => {
              callback(true, error)
            })
        }
      }
    }
  }
}

PS: I need to update docs

ricardogobbosouza commented 3 years ago

47