Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo wont connect after page refresh #56

Open
acidjazz opened this issue May 30, 2021 · 7 comments
Open

Echo wont connect after page refresh #56

acidjazz opened this issue May 30, 2021 · 7 comments

Comments

@acidjazz
Copy link

acidjazz commented May 30, 2021

In order to get echo working after a page refresh I have to do this:

this.$echo.options.broadcaster = this.$echo.config.broadcaster
await this.$echo.connect()

it works when the user logs in, but after a refresh it stops and options.broadcaster is null, and connect isnt run again.

i am on version alpha5 with the latest auth-next, my config is:

  echo: {
    broadcaster: 'pusher',
    key: process.env.PUSHER_APP_KEY,
    cluster: process.env.PUSHER_APP_CLUSTER,
    authEndpoint: `${process.env.API_URL}/broadcasting/auth`,
    encrypted: true,
    authModule: true,
    connectOnLogin: true,
    disconnectOnLogout: true,
  },
@acidjazz
Copy link
Author

here is a plugin I wrote for this work-around until we have an official fix for anyone that would like it.

import { Echo } from '@nuxtjs/laravel-echo'

export default async function ({ $echo }: { $echo: Echo }) {
  if ($echo.options.broadcaster !== $echo.config.broadcaster) {
    $echo.options.broadcaster = $echo.config.broadcaster
    await $echo.connect()
  }
}

@acidjazz
Copy link
Author

acidjazz commented Jul 6, 2021

@ricardogobbosouza any progress on this?

@devzom
Copy link

devzom commented Aug 6, 2021

here is a plugin I wrote for this work-around until we have an official fix for anyone that would like it.

import { Echo } from '@nuxtjs/laravel-echo'

export default async function ({ $echo }: { $echo: Echo }) {
  if ($echo.options.broadcaster !== $echo.config.broadcaster) {
    $echo.options.broadcaster = $echo.config.broadcaster
    await $echo.connect()
  }
}

In which point are You running this script? as a echo plugin or nuxt.config plugins or maybe $auth plugin?

@acidjazz
Copy link
Author

acidjazz commented Aug 6, 2021

@devzom an echo plugin:

  // Doc: https://github.com/nuxt-community/laravel-echo
  echo: {
    broadcaster: 'pusher',
    key: process.env.PUSHER_APP_KEY,
    cluster: process.env.PUSHER_APP_CLUSTER,
    authEndpoint: `${process.env.API_URL}/broadcasting/auth`,
    encrypted: true,
    authModule: true,
    connectOnLogin: true,
    disconnectOnLogout: true,
    plugins: [
      '@/plugins/echo',
    ],

@SilvioDoMine
Copy link

This is still happening on ^2.0.0-alpha.5, and this workarround seems to work.

@ssgnoe
Copy link

ssgnoe commented Dec 5, 2022

Had the same issue, your workaround did not fully work, so I changed a little bit for me. Imported the plugin as you explained, but the params brought me an error, so I switched like this, now working well. Hope it helps others ;)

export default async function ($nuxt) {
  if ($nuxt.$echo.options.broadcaster !== $nuxt.$echo.config.broadcaster) {
    $nuxt.$echo.options.broadcaster = $nuxt.$echo.config.broadcaster
    await $nuxt.$echo.connect()
  }
}

@dloused
Copy link

dloused commented Dec 14, 2022

Doing this defies the purpose of connectOnLogin as a connection will be made on page refresh even if the user is not logged in.
Include in your 'if' statement an auth check and you are good to go.

if ($nuxt.$echo.options.broadcaster !== $nuxt.$echo.config.broadcaster && $nuxt.$auth.user)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants