nuxt-community / laravel-echo-module

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

Issues while trying to connect Presence/Private Channels with authModule (Sanctum & Soketi) #73

Closed pexch closed 2 years ago

pexch commented 2 years ago

I am using Soketi as the server to receive requests. It seems that public channels work fine, but when I enable auth for presence/private channels, I end up running into the issue below. I am using Sanctum for authentication, I've enabled the required configuration for Laravel for Sanctum to work with the authEndpoint below.

Also I am using Cookie based Sessions, not tokens

nuxt.config.js

buildModules: [
  ...
  '@nuxtjs/laravel-echo',
],

echo: {
    broadcaster: 'pusher',
    authEndpoint : 'http://127.0.0.1:8000/api/broadcasting/auth',
    authModule: true,
    wsHost: '127.0.0.1',
    wsPort: 6001,
    key: 'my_key',
    encrypted: true,
    enableLogging: false,
    connectOnLogin: false,
    disconnectOnLogout: false,
    disableStats: false,
    forceTLS: false
  }

Error:

[x] POST http://127.0.0.1:8000/api/broadcasting/auth 401 (Unauthorized)
pexch commented 2 years ago

If I do something like:

nuxt.config.js

echo: {
    ...
   connectOnLogin: true,
}

Then I get:

Error:

[x] Refused to set unsafe header "referer" - pusher.js?782e:863
[x] POST http://127.0.0.1:8000/api/broadcasting/auth 401 (Unauthorized) - pusher.js?782e:896
trocker commented 2 years ago

@flyingspoon - did you figure out an answer to this?

pexch commented 2 years ago

@flyingspoon - did you figure out an answer to this?

Yes, I solved it by making my own version of laravel-echo. I believe if I remember correctly, I ended up utilizing a specific version of Echo (might be wrong), then re-coded parts of this plugin so it works with Laravel 9x.

If you would like to see it I can post it later today, it gets the job done! :)

trocker commented 2 years ago

If you would like to see it I can post it later today, it gets the job done! :)

@flyingspoon - yes! that would be extremely helpful! :)

pexch commented 2 years ago

If you would like to see it I can post it later today, it gets the job done! :)

@flyingspoon - yes! that would be extremely helpful! :)

You can find the code below, I made it work for Soketi & Laravel Echo within Nuxt 2x: https://github.com/flyingspoon/nuxt-echo

I last touched it when I opened this issue which was in May. So I have written down what I could remember, sorry if I have missed out anything! Good luck, and happy coding! 👍