'Centrifuge + React

In our app we use centrifuge as a web socket connection + react. When it is time to refresh token, I use config function - onRefresh, then I receive new token and set it.

refreshHeaders: { Authorization: `Bearer ${localStorage.getItem("act")}` },
  onRefresh: async function (ctx, cb) {
    try {
      await axios
        .post(`${BASE_URL}/centrifugo/refresh`, null, {
          headers: {
            Authorization: `Bearer ${localStorage.getItem("act")}`,
          },
        })
        .then((data) => {
          centrifuge.setToken(data.token);
        });
    } catch {
      centrifuge.disconnect();
      console.log("resfresh failed 1");
    }
  },

But in ws connection I got an error - code:109, token expired What is wrong in my way?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source