diff options
author | Wu Cheng-Han | 2017-01-15 17:23:19 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2017-01-15 17:23:19 +0800 |
commit | f2a441061bb5b96d3b90faa580d2ea2b5fb1266f (patch) | |
tree | a6ab91dc507cd9db35d6237453b0a009cf36f997 /public | |
parent | 3cf40a8dec96af3710a5945dde693fdc949f31af (diff) |
Fix checkLoginStateChanged might fall into infinite loop while calling loginStateChangeEvent
Diffstat (limited to '')
-rw-r--r-- | public/js/common.js | 10 |
1 files 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, |