From ffb3e2acc668d48e91721a38ded30e22a7769d6b Mon Sep 17 00:00:00 2001 From: Trenton Zimmer <66042448+trmazi@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:00:17 -0400 Subject: [PATCH] Rewrite auth flow, add greetings. fix auth bug --- .env.development | 4 ++-- .env.production | 2 +- public/data-sources/changelog.json | 3 ++- src/constants/greetings.json | 25 ++++++++++++++++++++++ src/layouts/LayoutAuthenticated.vue | 16 ++++++-------- src/stores/auth/index.js | 33 ----------------------------- src/stores/main.js | 29 +++++++------------------ 7 files changed, 44 insertions(+), 68 deletions(-) delete mode 100644 src/stores/auth/index.js diff --git a/.env.development b/.env.development index cd1c9c3..ec58bd3 100644 --- a/.env.development +++ b/.env.development @@ -1,5 +1,5 @@ -VITE_APP_VERSION="3.0.28" -VITE_API_URL="http://10.5.7.5:8000/" +VITE_APP_VERSION="3.0.30" +VITE_API_URL="http://localhost:8000/" VITE_API_KEY="your_api_key_should_be_here" VITE_ASSET_PATH="/assets" VITE_GAME_ASSET_PATH="https://cdn.phaseii.network/file/PhaseII/game-assets" diff --git a/.env.production b/.env.production index 8682841..42c0c6d 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ -VITE_APP_VERSION="3.0.28" +VITE_APP_VERSION="3.0.30" VITE_API_URL="https://restfulsleep.phaseii.network" VITE_API_KEY="your_api_key_should_be_here" VITE_ASSET_PATH="https://cdn.phaseii.network/file/PhaseII/web-assets" diff --git a/public/data-sources/changelog.json b/public/data-sources/changelog.json index 1194a41..c4101fd 100644 --- a/public/data-sources/changelog.json +++ b/public/data-sources/changelog.json @@ -28,5 +28,6 @@ "3.0.26": ["- (Minor) Game player table is more sortable", "- (Minor) Greetings now support custom styling", "- (Minor) Added the first styled greeting"], "3.0.27": ["- (Major) Profile data exporting added.", "- (Minor) More work for rivals."], "3.0.28": ["- (Major) Full support for rivals across applicable games", "- (Major) Move from Vue Hash routing to standard routing", "- (Bugfix) Fix issue when customizing on iOS"], - "3.0.29": ["- (Major) Finish arcade PASELI support", "- (Minor) Clean up arcade page, add button for opening owner", "- (Bugfix) Fix table upper curved edges"] + "3.0.29": ["- (Major) Finish arcade PASELI support", "- (Minor) Clean up arcade page, add button for opening owner", "- (Bugfix) Fix table upper curved edges"], + "3.0.30": ["- (Major) Rewrite auth flow at backend and frontend", "- (Minor) Add auth to all api calls", "- (Bugfix) Fix bad user auth bug", "- (Minor) Add more greetings"] } \ No newline at end of file diff --git a/src/constants/greetings.json b/src/constants/greetings.json index bdb8bb1..04e213e 100644 --- a/src/constants/greetings.json +++ b/src/constants/greetings.json @@ -575,5 +575,30 @@ "header": "You are now under my control, .", "comment": "Do as I say.", "class": "animated-text bg-linear-to-tl from-fuchsia-600 via-pink-700 to-purple-600 bg-clip-text text-transparent" + }, + { + "author": "Azui", + "header": "We'll meet again, .", + "comment": "Challenge the next GALAXY BRAVE!" + }, + { + "author": "cameron44251", + "header": "Hey, ", + "comment": "Did you know that the low taper fade meme is still massive?" + }, + { + "author": "PopDaCorn", + "header": "Welcome home, !", + "comment": "Remember to drink water <3. Stay hydrated!" + }, + { + "author": "BELOVED", + "header": "You'll be okay, .", + "comment": "Take care of yourself." + }, + { + "author": "RyogAkari", + "header": "Greetings, .", + "comment": "You tawt you taw a PASELI Cat." } ] diff --git a/src/layouts/LayoutAuthenticated.vue b/src/layouts/LayoutAuthenticated.vue index e1f34b4..d2f3ef3 100644 --- a/src/layouts/LayoutAuthenticated.vue +++ b/src/layouts/LayoutAuthenticated.vue @@ -23,19 +23,18 @@ import NavBar from "@/components/NavBar.vue"; import NavBarItemPlain from "@/components/NavBarItemPlain.vue"; import AsideMenu from "@/components/Menus/AsideMenu.vue"; import FooterBar from "@/components/FooterBar.vue"; -import { loadUserAuthKey, deleteUserAuthKey } from "@/stores/auth"; import { gameData } from "@/constants"; // import BaseButton from "@/components/BaseButton.vue"; const router = useRouter(); const route = useRoute(); -const userKey = loadUserAuthKey(); -if (!userKey) { - router.push({ - name: "login", - }); -} +// need to reimplement this... +// if (!userKey) { +// router.push({ +// name: "login", +// }); +// } const mainStore = useMainStore(); onMounted(async () => { @@ -43,7 +42,6 @@ onMounted(async () => { const validSession = await mainStore.loadUser(); if (!validSession) { mainStore.deleteUserSession(); - deleteUserAuthKey(); router.push({ name: "login", }); @@ -51,7 +49,6 @@ onMounted(async () => { } catch (error) { console.error("Failed to check SessionID:", error); mainStore.deleteUserSession(); - deleteUserAuthKey(); router.push({ name: "login", }); @@ -114,7 +111,6 @@ router.beforeEach(() => { const menuClick = (event, item) => { if (item.isLogout) { mainStore.deleteUserSession(); - deleteUserAuthKey(); router.push({ name: "login", }); diff --git a/src/stores/auth/index.js b/src/stores/auth/index.js deleted file mode 100644 index 3c6c786..0000000 --- a/src/stores/auth/index.js +++ /dev/null @@ -1,33 +0,0 @@ -import Cookies from "js-cookie"; - -export function loadUserAuthKey() { - try { - const encryptedKey = Cookies.get("userAuthKey"); - return encryptedKey; - } catch (error) { - this.errorCode = error.message; - throw error; - } -} - -export function saveUserAuthKey(sessionId, expires) { - try { - Cookies.set("userAuthKey", sessionId, { - expires: expires, - path: "", - sameSite: "strict", - }); - } catch (error) { - this.errorCode = error.message; - throw error; - } -} - -export function deleteUserAuthKey() { - try { - Cookies.remove("userAuthKey"); - } catch (error) { - this.errorCode = error.message; - throw error; - } -} diff --git a/src/stores/main.js b/src/stores/main.js index a5038eb..2f2de53 100644 --- a/src/stores/main.js +++ b/src/stores/main.js @@ -1,6 +1,5 @@ import { defineStore } from "pinia"; import axios from "axios"; -import { loadUserAuthKey, saveUserAuthKey } from "@/stores/auth"; export const useMainStore = defineStore("main", { state: () => ({ @@ -27,9 +26,6 @@ export const useMainStore = defineStore("main", { /* Field focus with ctrl+k (to register only once) */ isFieldFocusRegistered: false, - /* Authentication keys */ - userAuthKey: null, // Will be loaded and decrypted from cookies - /* Loading state */ isLoading: false, isSaving: false, @@ -135,8 +131,8 @@ export const useMainStore = defineStore("main", { const baseHeaders = { "App-Auth-Key": apiKey, - "User-Auth-Key": loadUserAuthKey(), }; + axios.defaults.withCredentials = true; const headers = { ...baseHeaders, ...extraHeaders }; @@ -180,6 +176,10 @@ export const useMainStore = defineStore("main", { async fetchAllNews() { if (!this.loadedNews) { + while (!this.userId) { + await new Promise((resolve) => setTimeout(resolve, 200)); + } + try { const data = await this.callApi("/news"); this.loadedNews = data.slice(0, 2); @@ -194,12 +194,8 @@ export const useMainStore = defineStore("main", { }, async checkUserSession() { - const request = { - sessionId: loadUserAuthKey(), - }; - try { - const data = await this.callApi(`/auth/session`, "GET", request); + const data = await this.callApi(`/auth/session`, "GET"); return data; } catch (error) { console.log("Error checking session:", error); @@ -208,17 +204,8 @@ export const useMainStore = defineStore("main", { }, async deleteUserSession() { - if (!loadUserAuthKey()) { - this.userLoaded = false; - return null; - } - - const request = { - sessionId: loadUserAuthKey(), - }; - try { - const data = await this.callApi(`/auth/session`, "DELETE", request); + const data = await this.callApi(`/auth/session`, "DELETE"); this.userLoaded = false; return data; } catch (error) { @@ -231,12 +218,12 @@ export const useMainStore = defineStore("main", { const request = { username: username, password: password, + remember: remember, // the 5th of November }; try { const data = await this.callApi(`/auth/session`, "POST", request); if (data && data.status === "success") { - saveUserAuthKey(data.sessionId, remember ? 30 : 1); return true; } else { alert("Incorrect username or password!");