Skip to content

Commit 848321c

Browse files
authored
Merge pull request #138 from os2display/feature/2804-no-error-when-no-token
Avoid ER105 in url when no token exists in local storage
2 parents 4ca840c + b17739c commit 848321c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- [#138](https://github.com/os2display/display-client/pull/138)
8+
- Avoided setting ER105 in url when no token exists in local storage.
79
- [#137](https://github.com/os2display/display-client/pull/137)
810
- Add `no-cache´ directive to nginx setup.
911

src/service/token-service.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ class TokenService {
5353
getExpireState = () => {
5454
const expire = appStorage.getTokenExpire();
5555
const issueAt = appStorage.getTokenIssueAt();
56+
const token = appStorage.getToken();
57+
58+
if (expire === null) {
59+
return constants.NO_EXPIRE;
60+
}
61+
if (issueAt === null) {
62+
return constants.NO_ISSUED_AT;
63+
}
64+
if (token === null) {
65+
return constants.NO_TOKEN;
66+
}
5667

5768
const timeDiff = expire - issueAt;
5869
const nowSeconds = Math.floor(new Date().getTime() / 1000);
@@ -121,11 +132,11 @@ class TokenService {
121132
checkToken = () => {
122133
const expiredState = this.getExpireState();
123134

124-
if (expiredState === constants.TOKEN_EXPIRED) {
135+
if ([constants.NO_EXPIRE, constants.NO_ISSUED_AT, constants.NO_TOKEN].includes(expiredState)) {
136+
// Ignore. No token saved in storage.
137+
} else if (expiredState === constants.TOKEN_EXPIRED) {
125138
statusService.setError(constants.ERROR_TOKEN_EXPIRED);
126-
} else if (
127-
expiredState === constants.TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED
128-
) {
139+
} else if (expiredState === constants.TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED) {
129140
statusService.setError(
130141
constants.ERROR_TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED
131142
);

src/util/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const constants = {
1414
ERROR_RELEASE_FILE_NOT_LOADED: 'ER104', // Release file could not be loaded.
1515
ERROR_TOKEN_EXPIRED: 'ER105', // Token is expired.
1616
ERROR_TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED: 'ER106', // Token is valid but should have been refreshed.
17+
NO_TOKEN: 'NO_TOKEN',
18+
NO_EXPIRE: 'NO_EXPIRE',
19+
NO_ISSUED_AT: 'NO_ISSUED_AT',
1720
};
1821

1922
export default constants;

0 commit comments

Comments
 (0)