mirror of https://github.com/status-im/codimd.git
Fix checkLoginStateChanged might fall into infinite loop while calling loginStateChangeEvent
This commit is contained in:
parent
3cf40a8dec
commit
f2a441061b
|
@ -18,7 +18,8 @@ var checkAuth = false;
|
||||||
var profile = null;
|
var profile = null;
|
||||||
var lastLoginState = getLoginState();
|
var lastLoginState = getLoginState();
|
||||||
var lastUserId = getUserId();
|
var lastUserId = getUserId();
|
||||||
var loginStateChangeEvent = null;
|
|
||||||
|
window.loginStateChangeEvent = null;
|
||||||
|
|
||||||
function resetCheckAuth() {
|
function resetCheckAuth() {
|
||||||
checkAuth = false;
|
checkAuth = false;
|
||||||
|
@ -42,8 +43,7 @@ function setLoginState(bool, id) {
|
||||||
|
|
||||||
function checkLoginStateChanged() {
|
function checkLoginStateChanged() {
|
||||||
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
||||||
if(loginStateChangeEvent)
|
if(loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100);
|
||||||
loginStateChangeEvent();
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -65,8 +65,7 @@ function clearLoginState() {
|
||||||
|
|
||||||
function checkIfAuth(yesCallback, noCallback) {
|
function checkIfAuth(yesCallback, noCallback) {
|
||||||
var cookieLoginState = getLoginState();
|
var cookieLoginState = getLoginState();
|
||||||
if (checkLoginStateChanged())
|
if (checkLoginStateChanged()) checkAuth = false;
|
||||||
checkAuth = false;
|
|
||||||
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
||||||
$.get(serverurl + '/me')
|
$.get(serverurl + '/me')
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
|
@ -107,7 +106,6 @@ module.exports = {
|
||||||
profile: profile,
|
profile: profile,
|
||||||
lastLoginState: lastLoginState,
|
lastLoginState: lastLoginState,
|
||||||
lastUserId: lastUserId,
|
lastUserId: lastUserId,
|
||||||
loginStateChangeEvent: loginStateChangeEvent,
|
|
||||||
|
|
||||||
/* export functions */
|
/* export functions */
|
||||||
resetCheckAuth: resetCheckAuth,
|
resetCheckAuth: resetCheckAuth,
|
||||||
|
|
Loading…
Reference in New Issue