Skip to content

Commit f2a4410

Browse files
committed
Fix checkLoginStateChanged might fall into infinite loop while calling loginStateChangeEvent
1 parent 3cf40a8 commit f2a4410

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

public/js/common.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var checkAuth = false;
1818
var profile = null;
1919
var lastLoginState = getLoginState();
2020
var lastUserId = getUserId();
21-
var loginStateChangeEvent = null;
21+
22+
window.loginStateChangeEvent = null;
2223

2324
function resetCheckAuth() {
2425
checkAuth = false;
@@ -42,8 +43,7 @@ function setLoginState(bool, id) {
4243

4344
function checkLoginStateChanged() {
4445
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
45-
if(loginStateChangeEvent)
46-
loginStateChangeEvent();
46+
if(loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100);
4747
return true;
4848
} else {
4949
return false;
@@ -65,8 +65,7 @@ function clearLoginState() {
6565

6666
function checkIfAuth(yesCallback, noCallback) {
6767
var cookieLoginState = getLoginState();
68-
if (checkLoginStateChanged())
69-
checkAuth = false;
68+
if (checkLoginStateChanged()) checkAuth = false;
7069
if (!checkAuth || typeof cookieLoginState == 'undefined') {
7170
$.get(serverurl + '/me')
7271
.done(function (data) {
@@ -107,7 +106,6 @@ module.exports = {
107106
profile: profile,
108107
lastLoginState: lastLoginState,
109108
lastUserId: lastUserId,
110-
loginStateChangeEvent: loginStateChangeEvent,
111109

112110
/* export functions */
113111
resetCheckAuth: resetCheckAuth,

0 commit comments

Comments
 (0)