Skip to content

Commit

Permalink
fix: prevent request from repeating
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasPiano committed May 9, 2023
1 parent a4f9c67 commit aa0a0b8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/service/socket.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ class SocketioService {
}

async sendMessage(payload) {
const cacheWithMatchingPayload = Object.values(this._requestCache).find(
(x) => x.payload.message === payload.message
);

if (cacheWithMatchingPayload) {
console.debug(cacheWithMatchingPayload);

debugger;

return;
}

const request = uuidv4();

return new Promise((resolve, reject) => {
Expand All @@ -95,19 +107,19 @@ class SocketioService {
if (data.request) {
const { reject, resolve, payload } = this._requestCache[data.request];

delete this._requestCache[data.request];

if (data.error === "jwt expired") {
resolve();
await refreshToken();
await this.sendMessage({
...payload,
token: VueCookieNext.getCookie("access_token"),
});

resolve();

} else {
reject(data.error);
}

delete this._requestCache[data.request];
}
};

Expand Down

0 comments on commit aa0a0b8

Please sign in to comment.