Open acidjazz opened 3 years ago
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()
}
}
@ricardogobbosouza any progress on this?
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?
@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',
],
This is still happening on ^2.0.0-alpha.5
, and this workarround seems to work.
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()
}
}
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)
In order to get echo working after a page refresh I have to do this:
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 latestauth-next
, my config is: