From 026a5cfda75c17eb32b6a9b1f5b6ebce7e211821 Mon Sep 17 00:00:00 2001 From: singharaj usai Date: Wed, 9 Oct 2024 13:16:06 -0400 Subject: [PATCH] basic public pages for unauthorized users --- client/js/auth/auth.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/client/js/auth/auth.js b/client/js/auth/auth.js index 856b0df..546eb25 100644 --- a/client/js/auth/auth.js +++ b/client/js/auth/auth.js @@ -81,6 +81,21 @@ const App = { const username = localStorage.getItem("username"); const currentPath = window.location.pathname; + // this whole public pages stuff need to be improved, requires whole site refactoring so unauthorized users can view other pages but certain div elements are hidden from them + const publicPages = [ + "/login", + "/register", + "/legal/terms-of-service", + "/legal/about", + "/legal/privacy-policy", + "/forum/home", + "/games", + ]; + + // all forum pages + const isForumPage = currentPath.startsWith("/forum/"); + + if (token && username) { $.ajax({ url: "/api/validate-session", @@ -109,13 +124,13 @@ const App = { console.error("Error validating session:", xhr.responseText); } this.logout(); - if (currentPath !== "/login" && currentPath !== "/register" && currentPath !== "/legal/terms-of-service" && currentPath !== "/legal/about" && currentPath !== "/legal/privacy-policy") { + if (!publicPages.includes(currentPath) && !isForumPage) { window.location.href = "/login"; } }, }); } else { - if (currentPath !== "/login" && currentPath !== "/register" && currentPath !== "/legal/terms-of-service" && currentPath !== "/legal/about" && currentPath !== "/legal/privacy-policy") { + if (!publicPages.includes(currentPath) && !isForumPage) { window.location.href = "/login"; } else { $("#loading").hide();