mirror of
https://github.com/PhaseII-eAmusement-Network/PhaseWeb3-Vue.git
synced 2026-03-21 17:54:26 -05:00
Rewrite auth flow, add greetings. fix auth bug
Some checks are pending
Build / build (push) Waiting to run
Some checks are pending
Build / build (push) Waiting to run
This commit is contained in:
parent
7bbc2d2c77
commit
ffb3e2acc6
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
}
|
||||
|
|
@ -575,5 +575,30 @@
|
|||
"header": "You are now under my control, <username>.",
|
||||
"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, <username>.",
|
||||
"comment": "Challenge the next GALAXY BRAVE!"
|
||||
},
|
||||
{
|
||||
"author": "cameron44251",
|
||||
"header": "Hey, <username>",
|
||||
"comment": "Did you know that the low taper fade meme is still massive?"
|
||||
},
|
||||
{
|
||||
"author": "PopDaCorn",
|
||||
"header": "Welcome home, <username>!",
|
||||
"comment": "Remember to drink water <3. Stay hydrated!"
|
||||
},
|
||||
{
|
||||
"author": "BELOVED",
|
||||
"header": "You'll be okay, <username>.",
|
||||
"comment": "Take care of yourself."
|
||||
},
|
||||
{
|
||||
"author": "RyogAkari",
|
||||
"header": "Greetings, <username>.",
|
||||
"comment": "You tawt you taw a PASELI Cat."
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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!");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user