From f2a441061bb5b96d3b90faa580d2ea2b5fb1266f Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Sun, 15 Jan 2017 17:23:19 +0800 Subject: Fix checkLoginStateChanged might fall into infinite loop while calling loginStateChangeEvent --- public/js/common.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/public/js/common.js b/public/js/common.js index f5bfc8ec..7eee1071 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -18,7 +18,8 @@ var checkAuth = false; var profile = null; var lastLoginState = getLoginState(); var lastUserId = getUserId(); -var loginStateChangeEvent = null; + +window.loginStateChangeEvent = null; function resetCheckAuth() { checkAuth = false; @@ -42,8 +43,7 @@ function setLoginState(bool, id) { function checkLoginStateChanged() { if (getLoginState() != lastLoginState || getUserId() != lastUserId) { - if(loginStateChangeEvent) - loginStateChangeEvent(); + if(loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100); return true; } else { return false; @@ -65,8 +65,7 @@ function clearLoginState() { function checkIfAuth(yesCallback, noCallback) { var cookieLoginState = getLoginState(); - if (checkLoginStateChanged()) - checkAuth = false; + if (checkLoginStateChanged()) checkAuth = false; if (!checkAuth || typeof cookieLoginState == 'undefined') { $.get(serverurl + '/me') .done(function (data) { @@ -107,7 +106,6 @@ module.exports = { profile: profile, lastLoginState: lastLoginState, lastUserId: lastUserId, - loginStateChangeEvent: loginStateChangeEvent, /* export functions */ resetCheckAuth: resetCheckAuth, -- cgit v1.2.3