nuxt-community / laravel-echo-module

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

v2.0.0-alpha.1 with laravel sanctum is broken #48

Open yoelpc4 opened 3 years ago

yoelpc4 commented 3 years ago

Hi @ricardogobbosouza I have these package versions

dependencies:

  1. @nuxtjs/auth-next 5.0.0-1613647907.37b1156
  2. nuxt ^v2.15.4
  3. pusher-js ^7.0.3

devDependencies

  1. @nuxtjs/laravel-echo ^2.0.0-alpha.1

with the following nuxt config

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

echo: {
    authEndpoint: '/laravel/broadcasting/auth',
    authModule: true,
    broadcaster: 'pusher',
    cluster: 'ap1',
    connectOnLogin: true,
    disconnectOnLogout: true,
    encrypted: true,
    forceTLS: true,
    key: process.env.PUSHER_APP_KEY,
},

modules: [
    ...
    '@nuxtjs/auth-next',
],

As you suggest to install v2.0.0-alpha.1 on recent issue #47 along with nuxt auth next laravel sanctum strategy, it resulted ReferenceError "location is not defined" on this line: https://github.com/nuxt-community/laravel-echo-module/blob/7a5e78ac41f9bf27d0e1b38b86358f4f6d306bc0/src/runtime/echo.ts#L38

ricardogobbosouza commented 3 years ago

Hi @yoelpc4 Thanks for reporting I will correct

ricardogobbosouza commented 3 years ago

Hi @yoelpc4 Try ^2.0.0-alpha.2

yoelpc4 commented 3 years ago

Hi @ricardogobbosouza

It seems that the @nuxtjs/laravel-echo plugin isn't calling connect method at all although I've logged in through nuxt auth.

nuxt.config.js

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

echo: {
    authModule: true,
    broadcaster: 'pusher',
    cluster: 'ap1',
    connectOnLogin: true,
    disconnectOnLogout: true,
    encrypted: true,
    forceTLS: true,
    key: '...',
    optionsPath: './laravel-echo.options.js',
},

modules: [
    ...
    '@nuxtjs/auth-next',
],

with the following laravel-echo.options.js

export default ({ $axios }) => ({
  authorizer: (channel) => ({
    authorize: (socketId, authorizerCallback) =>
      $axios
        .post('/backend/api/broadcasting/auth', {
          channel_name: channel.name,
          socket_id: socketId,
        })
        .then(({ data }) => authorizerCallback(false, data))
        .catch((error) => authorizerCallback(true, error)),
  }),
  onAfterConnect() {
    console.log('laravel echo connected')
  },
})

Because the onAfterConnect hook is not invoked and I've checked out on pusher debug console there's no connection logs at all.

radudiaconu0 commented 3 years ago

I get 401 Unauthorized error

ricardogobbosouza commented 3 years ago

Hi @yoelpc4 Sorry, had a problem with the options.

Try ^2.0.0-alpha.4

radudiaconu0 commented 3 years ago

@ricardogobbosouza now it doesnt connect to my websocket server(laravel-websockets)

ricardogobbosouza commented 3 years ago

@radudiaconu0 Please provide a repository

radudiaconu0 commented 3 years ago

@ricardogobbosouza

https://github.com/radudiaconu0/cheermeapp-frontend/

ricardogobbosouza commented 3 years ago

Hi @radudiaconu0 I couldn't even register for your application, I configured the frontend and the backend

https://github.com/radudiaconu0/cheermeapp-frontend/ https://github.com/radudiaconu0/cheermeapp-backend/

Always with error CSRF token mismatch.

radudiaconu0 commented 3 years ago

@ricardogobbosouza set domains from cheermeapp.test to localhost. In laravel app and nuxtapp

alitnk commented 3 years ago
"@nuxtjs/laravel-echo": "^2.0.0-alpha.5",
"nuxt": "^2.14.12",
"@nuxtjs/auth-next": "5.0.0-1613647907.37b1156",
"pusher-js": "^7.0.3",

in nuxt.config.js:

echo: {
    ...
    broadcaster: 'pusher',
    authModule: true,
}

My connector is set to NullConnector when I set authModule to true, But when I set it back to false, it's a PusherConnector again. Am I doing something wrong?

Shar0w commented 3 years ago

Hello. Does not work for me either

When I set authModule to true, I get this error:

TypeError: Cannot read property 'bind' of undefined at Echo.watchAuthState (echo.js?38ae:55) at Echo._callee$ (echo.js?38ae:13) at tryCatch (runtime.js?96cf:63) at Generator.invoke [as _invoke] (runtime.js?96cf:293) at Generator.eval [as next] (runtime.js?96cf:118) at asyncGeneratorStep (asyncToGenerator.js?1da1:3) at _next (asyncToGenerator.js?1da1:25)

djoks commented 3 years ago

Having the same issue. Looks like v2 is buggy.

Shar0w commented 3 years ago

Having the same issue. Looks like v2 is buggy.

Yes. That's why I used v1