Skip to content

Commit

Permalink
Merge pull request #138 from os2display/feature/2804-no-error-when-no…
Browse files Browse the repository at this point in the history
…-token

Avoid ER105 in url when no token exists in local storage
  • Loading branch information
tuj authored Oct 23, 2024
2 parents 4ca840c + b17739c commit 848321c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.

## Unreleased

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

Expand Down
19 changes: 15 additions & 4 deletions src/service/token-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ class TokenService {
getExpireState = () => {
const expire = appStorage.getTokenExpire();
const issueAt = appStorage.getTokenIssueAt();
const token = appStorage.getToken();

if (expire === null) {
return constants.NO_EXPIRE;
}
if (issueAt === null) {
return constants.NO_ISSUED_AT;
}
if (token === null) {
return constants.NO_TOKEN;
}

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

if (expiredState === constants.TOKEN_EXPIRED) {
if ([constants.NO_EXPIRE, constants.NO_ISSUED_AT, constants.NO_TOKEN].includes(expiredState)) {
// Ignore. No token saved in storage.
} else if (expiredState === constants.TOKEN_EXPIRED) {
statusService.setError(constants.ERROR_TOKEN_EXPIRED);
} else if (
expiredState === constants.TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED
) {
} else if (expiredState === constants.TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED) {
statusService.setError(
constants.ERROR_TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED
);
Expand Down
3 changes: 3 additions & 0 deletions src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const constants = {
ERROR_RELEASE_FILE_NOT_LOADED: 'ER104', // Release file could not be loaded.
ERROR_TOKEN_EXPIRED: 'ER105', // Token is expired.
ERROR_TOKEN_VALID_SHOULD_HAVE_BEEN_REFRESHED: 'ER106', // Token is valid but should have been refreshed.
NO_TOKEN: 'NO_TOKEN',
NO_EXPIRE: 'NO_EXPIRE',
NO_ISSUED_AT: 'NO_ISSUED_AT',
};

export default constants;

0 comments on commit 848321c

Please sign in to comment.