|
|
|
@ -1,13 +1,26 @@
|
|
|
|
export function checkLogin() {
|
|
|
|
export function checkLogin() {
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
if (getSessionKey() !== null) {
|
|
|
|
var cookie = cookies[i].trim();
|
|
|
|
|
|
|
|
if (cookie.indexOf('session=') === 0) {
|
|
|
|
|
|
|
|
// The "session" cookie exists
|
|
|
|
// The "session" cookie exists
|
|
|
|
return true;
|
|
|
|
fetch('https://api.bb.gabefarrell.com/userinfo', {
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
|
|
'x-session-key': getSessionKey(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.then(data => data.json())
|
|
|
|
|
|
|
|
.then((r) => {
|
|
|
|
|
|
|
|
if (r.status !== 200) {
|
|
|
|
|
|
|
|
// key is invalid
|
|
|
|
|
|
|
|
handleLogout()
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// key is OK
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The "session" cookie doesn't exist
|
|
|
|
// The "session" cookie doesn't exist or is invalid
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|