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

FP-2297: Redirect to login after losing token #144

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
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