Skip to content

Commit 8c7e5ff

Browse files
authored
added date time and network status in sidebar (#536)
added date time and network status in sidebar
1 parent 6868057 commit 8c7e5ff

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

forms-flow-nav/src/sidenav/Sidebar.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@
270270
}
271271

272272
.date-time-network-container .date {
273-
font-size: 15px;
273+
font-size: 13px;
274274
color: #cbd5e0;
275-
margin-left: 10px;
275+
margin-left: 8px;
276276
margin-top: 4px;
277277
}
278278

forms-flow-rsbcservice/src/services/offlineSubmissions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class OfflineSubmissions {
5656
/**
5757
* Initializes Keycloak if it's not already initialized and retry token.
5858
*/
59-
private static async retryToken(): Promise<void> {
59+
public static async retryToken(): Promise<void> {
6060
const instance = KeycloakService.getInstance(
6161
KEYCLOAK_URL_AUTH,
6262
KEYCLOAK_URL_REALM,

forms-flow-service/src/keycloak/KeycloakService.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,57 @@ import {
6767
return 60000;
6868
}
6969
}
70-
70+
71+
private keycloackUpdateToken(timeEnabled = false): void {
72+
this.kc
73+
?.updateToken(-1)
74+
.then((refreshed) => {
75+
if (refreshed) {
76+
console.log("Token refreshed!");
77+
this.token = this.kc.token;
78+
StorageService.save(StorageService.User.AUTH_TOKEN, this.token!);
79+
if (this.kc.refreshToken && APPLICATION_NAME === "roadsafety") {
80+
StorageService.save(
81+
StorageService.User.REFRESH_TOKEN,
82+
HelperServices.encrypt(this.kc.refreshToken)
83+
);
84+
} else {
85+
console.info(
86+
"Refreshing Tokens - Not storing the refresh token."
87+
);
88+
}
89+
this.refreshToken();
90+
} else {
91+
console.log("Token is still valid!");
92+
}
93+
})
94+
.catch((err) => {
95+
console.error("Keycloak token update failed!", err);
96+
this.handleTokenRefreshFailure();
97+
})
98+
.finally(() => {
99+
if (timeEnabled) {
100+
clearInterval(this.timerId);
101+
}
102+
});
103+
}
104+
71105
/**
72106
* Refresh the keycloak token before expiring
73107
*/
74108
private refreshToken(skipTimer: boolean = false): void {
75-
this.timerId = setInterval(() => {
76-
if (!navigator.onLine) {
77-
console.debug("Offline: Skipping token refresh.");
78-
return;
79-
}
80-
81-
this.kc
82-
?.updateToken(-1)
83-
.then((refreshed) => {
84-
if (refreshed) {
85-
console.log("Token refreshed!");
86-
clearInterval(this.timerId);
87-
this.token = this.kc.token;
88-
StorageService.save(StorageService.User.AUTH_TOKEN, this.token!);
89-
if (this.kc.refreshToken && APPLICATION_NAME === "roadsafety") {
90-
StorageService.save(StorageService.User.REFRESH_TOKEN, HelperServices.encrypt(this.kc.refreshToken));
91-
} else {
92-
console.info("Refreshing Tokens - Not storing the refresh token.");
93-
}
94-
this.refreshToken();
95-
} else {
96-
console.log("Token is still valid!");
97-
}
98-
})
99-
.catch((err) => {
100-
console.error("Keycloak token update failed!", err);
101-
clearInterval(this.timerId);
102-
this.handleTokenRefreshFailure();
103-
});
104-
}, (!skipTimer && APPLICATION_NAME === "roadsafety") ? this.getTokenExpireTime() : 0);
109+
this.timerId = setInterval(
110+
() => {
111+
if (!navigator.onLine) {
112+
console.debug("Offline: Skipping token refresh.");
113+
return;
114+
}
115+
this.keycloackUpdateToken(true);
116+
},
117+
!skipTimer && APPLICATION_NAME === "roadsafety"
118+
? this.getTokenExpireTime()
119+
: 0
120+
);
105121
}
106122

107123
/**
@@ -146,7 +162,7 @@ import {
146162
}
147163
}
148164
this.isWaitingForOnline = false;
149-
this.refreshToken(skipTimer);
165+
this.keycloackUpdateToken();
150166
};
151167

152168

0 commit comments

Comments
 (0)