Validate token on initial load
This commit is contained in:
parent
cd0baa7605
commit
4498ed002a
|
@ -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
|
||||
});
|
||||
});
|
||||
}
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue