Validate token on initial load

This commit is contained in:
Robbie Antenesse 2019-10-17 21:35:32 -06:00
parent cd0baa7605
commit 4498ed002a
2 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,8 @@ export const appListeners = (app, state, emitter) => {
emitter.emit('render', () => { });
});
emitter.emit('render'); // This should hopefully only run once after the DOM is loaded. It prevents routing issues where 'render' hasn't been defined yet
app.checkIfLoggedIn(state).then(isLoggedIn => {
emitter.emit('render'); // This should hopefully only run once after the DOM is loaded. It prevents routing issues where 'render' hasn't been defined yet
});
});
}

View File

@ -19,4 +19,19 @@ export const appUtilities = (app) => {
savedSettings[settingsKey] = value;
return window.localStorage.setItem('settings', JSON.stringify(savedSettings));
}
app.checkIfLoggedIn = (appState) => {
return fetch('/api/account/validate', { method: 'post' })
.then(response => response.json())
.then(response => {
if (response.error !== false) {
console.warn(response);
return false;
}
console.info(response.message);
appState.isLoggedIn = true;
return true;
});
}
}