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

Avoid ER105 in url when no token exists in local storage #138

Merged
merged 1 commit into from
Oct 23, 2024
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
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;
Loading