Skip to content

Commit

Permalink
Redirect to login after losing token
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelnogueiramov authored and quirinpa committed Sep 13, 2023
1 parent 36384c3 commit f30e429
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 1.1.2

- [FP-2297: Redirect to login after losing token](https://movai.atlassian.net/browse/FP-2297)
- [FP-2049: Use Roles v2 endpoint](https://movai.atlassian.net/browse/FP-2049)
- [FP-2202: Robot power off but online in the fleetboard alerts window](https://movai.atlassian.net/browse/FP-2202)
- [FP-2233: De-activating alerts is not removing alerts in real-time](https://movai.atlassian.net/browse/FP-2233)
Expand Down
10 changes: 8 additions & 2 deletions src/api/Database/WSSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class WSSub {
this.RESEND_TIMEOUT = 1000;
this.RETRIES = 3;
this.NORMAL_CLOSE_EVT = 1000;

// supported commands
this.commands = {
SUBSCRIBE: "subscribe",
Expand Down Expand Up @@ -321,6 +321,10 @@ class WSSub {
return connectionPromise;
};

handleFalseConnection = (statusText) => {
if(statusText === "Token must be a string!") return Authentication.logout();
}

/**
* Check connection state by doing requests
* @returns Heartbeat fetch promise
Expand All @@ -330,12 +334,14 @@ class WSSub {
method: "POST",
body: JSON.stringify({ token: getToken() })
})
.then(_res => {
.then(res => {
if (!res.ok && res.status !== 200) return this.handleFalseConnection(res.statusText);
if (this.connectionState === CONNECTION.online) return;
this.connectionState = CONNECTION.online;
this.onOnline();
})
.catch(_err => {
console.warn(_err);
if (this.connectionState === CONNECTION.offline) return;
this.connectionState = CONNECTION.offline;
this.onOffline();
Expand Down

0 comments on commit f30e429

Please sign in to comment.