From ec09fb8bf1bb60c666724eb862f880473bbeac7a Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Tue, 18 Apr 2023 20:30:00 +0000 Subject: [PATCH] Fix session checking --- src/utils/utils.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index d547956..68824fc 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -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; }