fix another navbar bug

main
Gabe Farrell 3 years ago
parent 0d0cbc4e79
commit 7b7abf5f67

@ -1,25 +1,28 @@
export async function checkLogin() { export function checkLogin() {
var cookies = document.cookie.split(';'); var cookies = document.cookie.split(';');
if (getSessionKey() !== null) { if (getSessionKey() !== null) {
// The "session" cookie exists // The "session" cookie exists
let result = await fetch('https://api.bb.gabefarrell.com/userinfo', { fetch('https://api.bb.gabefarrell.com/userinfo', {
method: 'GET', method: 'GET',
headers: { headers: {
'x-session-key': getSessionKey(), 'x-session-key': getSessionKey(),
}, },
}) })
result = await result.json() .then(data => data.json())
if (result.status !== 200) { .then((result) => {
// key is invalid if (result.status !== 200) {
handleLogout() // key is invalid
return false handleLogout()
} else { return false
// key is OK } else {
return true // key is OK
} return true
}
})
} else {
// The "session" cookie doesn't exist or is invalid
return false;
} }
// The "session" cookie doesn't exist or is invalid
return false;
} }
export function getSessionKey() { export function getSessionKey() {

Loading…
Cancel
Save