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

Refreshed tokens not applied #53

Open
iranagame opened this issue Apr 28, 2021 · 1 comment
Open

Refreshed tokens not applied #53

iranagame opened this issue Apr 28, 2021 · 1 comment

Comments

@iranagame
Copy link

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?

@devzom
Copy link

devzom commented Sep 1, 2021

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?

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

2 participants