mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-07 21:48:14 -08:00
Fix session checking
This commit is contained in:
parent
befae76138
commit
ec09fb8bf1
1 changed files with 19 additions and 6 deletions
|
|
@ -1,13 +1,26 @@
|
|||
export function checkLogin() {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = cookies[i].trim();
|
||||
if (cookie.indexOf('session=') === 0) {
|
||||
if (getSessionKey() !== null) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue