mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-15 18:26:01 -07: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() {
|
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 or is invalid
|
||||||
// The "session" cookie doesn't exist
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue