laravel-echo-module
laravel-echo-module copied to clipboard
Refreshed tokens not applied
If socket has already connected through a valid token and token gets refresh after a while, the library still using the old token and that will cause 401 subscription_error on subscribe requests!
I'm experiencing this on socket.io adapter.
Any ideas on how solve this?
I experience the same issue due to working with nuxt-auth + laravelJWT refresh scheme. So dirty workaround for now it that I set actual access_token by settings actuall token on
mounted(){
this.$echo.options.auth.headers['Authorization'] = this.$auth.strategy.token.get()
... // logic to connect by $echo to channel
}
or better one I'm using right now:
plugin: axios.js
export default function ({ app, $axios }) {
$axios.onRequest(
async request => {
try {
if (app.$auth.strategy.token.status().expired()) {
await app.$auth.refreshTokens()
}
// set the Authorization header using the access token fetched from login config
const actualAuthToken = app.$auth.strategy.token.get()
request.headers['Authorization'] = actualAuthToken
app.$echo.options.auth.headers['Authorization'] =
actualAuthToken
app.$auth.strategy.token.sync()
} catch (e) {
console.error(e)
}
return request
},
error => {
return Promise.reject(error)
}
)
}
have found better fix?