Skip to content

Commit 5282a4a

Browse files
authored
Merge pull request #1648 from mercihabam/fix-auth
fix(frontend): redirect to the login screen when the session has expired or has been invalidated
2 parents e2b60de + e5406be commit 5282a4a

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function logout() {
2+
window.location.href = window.location.href;
3+
}

modules/core/navigation/navigation.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ async function navigate(url, loaderMessage) {
102102
if (!html || typeof html !== 'string') {
103103
throw new Error("Failed navigating to page, empty or invalid response body.");
104104
}
105+
106+
// load custom javascript
107+
const scripts = extractCustomScripts($(html));
108+
loadCustomScripts(scripts);
109+
110+
if (!hm_is_logged()) {
111+
logout();
112+
return;
113+
}
114+
105115
const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
106116
if (!titleMatch) {
107117
throw new Error("No <title> element found in response HTML");
@@ -127,10 +137,6 @@ async function navigate(url, loaderMessage) {
127137
cyphtMain = innerMain.prop('outerHTML');
128138
}
129139
document.title = title.replace(/<[^>]*>/g, '');
130-
131-
// load custom javascript
132-
const scripts = extractCustomScripts($(html));
133-
loadCustomScripts(scripts);
134140

135141
window.location.next = url;
136142

modules/core/site.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ var Hm_Ajax_Request = function() { return {
245245
if (hm_encrypt_ajax_requests()) {
246246
res = Hm_Utils.json_decode(Hm_Crypt.decrypt(res.payload));
247247
}
248-
if ((res.state && res.state == 'not callable') || !res.router_login_state) {
249-
this.fail(xhr, true);
248+
if ((res.status && res.status == 'not callable') || !res.router_login_state) {
249+
this.fail(xhr, true, !res.router_login_state);
250250
return;
251251
}
252252
if (Hm_Ajax.err_condition) {
@@ -277,7 +277,11 @@ var Hm_Ajax_Request = function() { return {
277277
return false;
278278
},
279279

280-
fail: function(xhr, not_callable) {
280+
fail: function(xhr, not_callable, shouldLogout) {
281+
if (shouldLogout) {
282+
logout();
283+
return;
284+
}
281285
if (not_callable === true || (xhr.status && xhr.status == 500)) {
282286
Hm_Notices.show('Server Error', 'danger');
283287
}

0 commit comments

Comments
 (0)