From 71717572341b3fe0557274cba77cb0d03204057a Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Sat, 2 Mar 2024 09:50:27 -0500 Subject: [PATCH 1/7] Debugging! --- src/stores/powerItems.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stores/powerItems.ts b/src/stores/powerItems.ts index c35a8a1..01cd9af 100644 --- a/src/stores/powerItems.ts +++ b/src/stores/powerItems.ts @@ -25,6 +25,7 @@ export const usePowerItems = defineStore('powerItems', () => { const FELLOW_POWER_ITEM_STORAGE = 'FELLOW_POWER_ITEM_STORAGE' const INTIMACY_POWER_ITEM_STORAGE = 'INTIMACY_POWER_ITEM_STORAGE' const apiBaseURL = inject(apiBaseURLKey)! + console.log(apiBaseURL) //#endregion //#region state From a4c98b18184c1f6cd70bf0ebf468ff482b5d389c Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Sat, 2 Mar 2024 10:11:05 -0500 Subject: [PATCH 2/7] Trying To Manually Load Config --- src/stores/powerItems.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/stores/powerItems.ts b/src/stores/powerItems.ts index 01cd9af..e6f2cdf 100644 --- a/src/stores/powerItems.ts +++ b/src/stores/powerItems.ts @@ -5,6 +5,8 @@ import { computed, ref, toRaw } from 'vue' import axiosRetry from 'axios-retry' import { apiBaseURL as apiBaseURLKey } from '@/types/ConfigSymbols' import { inject } from 'vue' +import { getConfig } from '@/services/siteConfig' +import type { Config } from '@/types/Config' const BLESSING = 1 const INTIMACY = 2 @@ -24,7 +26,14 @@ export const usePowerItems = defineStore('powerItems', () => { const BLESSING_POWER_ITEM_STORAGE = 'BLESSING_POWER_ITEM_STORAGE' const FELLOW_POWER_ITEM_STORAGE = 'FELLOW_POWER_ITEM_STORAGE' const INTIMACY_POWER_ITEM_STORAGE = 'INTIMACY_POWER_ITEM_STORAGE' - const apiBaseURL = inject(apiBaseURLKey)! + let apiBaseURL = inject(apiBaseURLKey)! + if (apiBaseURL === undefined) { + getConfig().then((conf: Config | null) => { + if (conf !== null) { + apiBaseURL = conf.apiBaseURL + } + }) + } console.log(apiBaseURL) //#endregion @@ -33,7 +42,7 @@ export const usePowerItems = defineStore('powerItems', () => { const fellowPowerItems = ref(new Map()) const intimacyPowerItems = ref(new Map()) //#endregion - + axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay From 42e9b2f62804a8f26944ec847e9187346d9ff5eb Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Sat, 2 Mar 2024 18:43:15 -0500 Subject: [PATCH 3/7] Why Is Config Broken On the Server? --- src/stores/powerItems.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/stores/powerItems.ts b/src/stores/powerItems.ts index e6f2cdf..b90c33e 100644 --- a/src/stores/powerItems.ts +++ b/src/stores/powerItems.ts @@ -50,6 +50,13 @@ export const usePowerItems = defineStore('powerItems', () => { //#region loaders async function fetchBlessingItems() { + getConfig().then((conf: Config | null) => { + if (conf !== null) { + apiBaseURL = conf.apiBaseURL + return conf + } + throw new Error("Could not fetch config") + }) axios .get(apiBaseURL + '/powerItems/byType/' + BLESSING + '/asMap', noCacheConfig) .then((resp) => { From 6eb298c0b9e1c48199c2852fe8d7665177a2aefa Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Sat, 2 Mar 2024 20:38:00 -0500 Subject: [PATCH 4/7] Debug --- src/stores/powerItems.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stores/powerItems.ts b/src/stores/powerItems.ts index b90c33e..d9a12d7 100644 --- a/src/stores/powerItems.ts +++ b/src/stores/powerItems.ts @@ -57,6 +57,7 @@ export const usePowerItems = defineStore('powerItems', () => { } throw new Error("Could not fetch config") }) + console.log("get: " + apiBaseURL) axios .get(apiBaseURL + '/powerItems/byType/' + BLESSING + '/asMap', noCacheConfig) .then((resp) => { From e6b3f4142f6bf7cffcbf744046b01a0a4612fdd6 Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Sat, 2 Mar 2024 20:45:51 -0500 Subject: [PATCH 5/7] Debug --- src/stores/powerItems.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stores/powerItems.ts b/src/stores/powerItems.ts index d9a12d7..b9e2c3d 100644 --- a/src/stores/powerItems.ts +++ b/src/stores/powerItems.ts @@ -52,6 +52,7 @@ export const usePowerItems = defineStore('powerItems', () => { async function fetchBlessingItems() { getConfig().then((conf: Config | null) => { if (conf !== null) { + console.log(conf) apiBaseURL = conf.apiBaseURL return conf } From a8e7e18bf919de87d2a0e72f252a2d7a35a89678 Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Sat, 2 Mar 2024 20:59:00 -0500 Subject: [PATCH 6/7] Cleanup Debugging Stuff --- src/stores/powerItems.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/stores/powerItems.ts b/src/stores/powerItems.ts index b9e2c3d..d2c25c1 100644 --- a/src/stores/powerItems.ts +++ b/src/stores/powerItems.ts @@ -34,7 +34,6 @@ export const usePowerItems = defineStore('powerItems', () => { } }) } - console.log(apiBaseURL) //#endregion //#region state @@ -50,15 +49,6 @@ export const usePowerItems = defineStore('powerItems', () => { //#region loaders async function fetchBlessingItems() { - getConfig().then((conf: Config | null) => { - if (conf !== null) { - console.log(conf) - apiBaseURL = conf.apiBaseURL - return conf - } - throw new Error("Could not fetch config") - }) - console.log("get: " + apiBaseURL) axios .get(apiBaseURL + '/powerItems/byType/' + BLESSING + '/asMap', noCacheConfig) .then((resp) => { From b822e4d321cffbb3bec5de4a48888e11b0a47f4c Mon Sep 17 00:00:00 2001 From: Annika Merris Date: Fri, 5 Apr 2024 23:09:46 -0400 Subject: [PATCH 7/7] Implemented a Basic Pass Of Post-login Redirecting --- public/config.json | 2 +- src/components/GlobalHeader.vue | 23 ++++++++++++- src/main.ts | 6 ++-- src/router/index.ts | 60 ++++++++++++++++++++------------- src/stores/general.ts | 34 +++++++++++++++++++ src/types/ConfigSymbols.ts | 5 ++- src/views/LoginView.vue | 48 +++++++++++++------------- src/views/PostLoginView.vue | 10 ++++++ src/views/TestView.vue | 1 - 9 files changed, 135 insertions(+), 54 deletions(-) create mode 100644 src/stores/general.ts create mode 100644 src/views/PostLoginView.vue diff --git a/public/config.json b/public/config.json index 1c24583..e89a2f4 100644 --- a/public/config.json +++ b/public/config.json @@ -1,5 +1,5 @@ { - "apiBaseURL": "http://coder.local.merr.is:3000", + "apiBaseURL": "http://coder.local.merr.is:3001", "oidcAuthority": "https://auth.joes.moosenet.work", "oidcClientID": "255988227184328707@isekai:_slow_life_calculator", "oidcProjectID": "255987963094106115" diff --git a/src/components/GlobalHeader.vue b/src/components/GlobalHeader.vue index fd1edfb..4ae83ce 100644 --- a/src/components/GlobalHeader.vue +++ b/src/components/GlobalHeader.vue @@ -1,7 +1,22 @@ diff --git a/src/main.ts b/src/main.ts index 18da9f9..4ece5fa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,7 +24,7 @@ const vuetify = createVuetify({ }) getConfig().then((conf: Config | null) => { - configureOidc().then((authentikAuth) => { + configureOidc().then((oidcAuth) => { if (conf === null) { throw new Error('config was null') } @@ -32,9 +32,9 @@ getConfig().then((conf: Config | null) => { app.provide(apiBaseURL, conf.apiBaseURL) - authentikAuth.startup().then((ok: boolean) => { + oidcAuth.startup().then((ok: boolean) => { if (ok) { - app.provide(oidc, authentikAuth) + app.provide(oidc, oidcAuth) const pinia = createPinia() diff --git a/src/router/index.ts b/src/router/index.ts index 0836a91..daa4c0d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,7 @@ import { configureOidc } from '@/services/authentikAuth' import { getConfig } from '@/services/siteConfig' import type { Config } from '@/types/Config' +import { LOGIN_RETURN_URL_STORAGE } from '@/types/ConfigSymbols' import type { OidcAuth } from 'vue-oidc-client/vue3' import { createRouter, createWebHistory } from 'vue-router' @@ -34,30 +35,43 @@ const router = createRouter({ path: '/intimacy-power', name: 'intimacy-power', component: () => import('@/views/IntimacyPowerView.vue') - } - // { - // path: '/test', - // name: 'test', - // component: () => import('@/views/TestView.vue') - // }, + }, + { + path: '/test', + name: 'test', + component: () => + hasRole('admin') ? import('@/views/TestView.vue') : import('@/views/NoAccess.vue') + }, - // { - // path: '/login', - // name: 'login', - // meta: { - // authName: oidcAuth.authName - // }, - // component: () => import('@/views/LoginView.vue') - // }, - // { - // path: '/admin', - // name: 'admin', - // meta: { - // authName: oidcAuth.authName - // }, - // component: () => - // hasRole('admin') ? import('@/views/Admin.vue') : import('@/views/NoAccess.vue') - // } + { + path: '/login', + name: 'login', + meta: { + authName: oidcAuth.authName + }, + component: () => import('@/views/LoginView.vue') + }, + { + path: '/admin', + name: 'admin', + meta: { + authName: oidcAuth.authName + }, + component: () => + hasRole('admin') ? import('@/views/Admin.vue') : import('@/views/NoAccess.vue') + }, + { + path: '/postLogin', + name: 'postLogin', + redirect: () => { + let redirectUrl = sessionStorage.getItem(LOGIN_RETURN_URL_STORAGE) + if (redirectUrl === "" || redirectUrl === null) { + redirectUrl = "/" + } + sessionStorage.removeItem(LOGIN_RETURN_URL_STORAGE) + return { path: redirectUrl } + } + } ] }) diff --git a/src/stores/general.ts b/src/stores/general.ts new file mode 100644 index 0000000..945062e --- /dev/null +++ b/src/stores/general.ts @@ -0,0 +1,34 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const useGeneralState = defineStore('general', () => { + const LOGIN_RETURN_URL_STORAGE = 'LOGIN_RETURN_URL_STORAGE' + + const loginReturnUrl = ref("") + + function setLoginReturnUrl(url: string) { + loginReturnUrl.value = url + localStorage.setItem( + LOGIN_RETURN_URL_STORAGE, + loginReturnUrl.value, + ) + } + + function getLoginReturnUrl(): string { + const storedUrl = localStorage.getItem(LOGIN_RETURN_URL_STORAGE) + if (storedUrl === null || storedUrl === undefined || storedUrl === "") { + localStorage.removeItem(LOGIN_RETURN_URL_STORAGE) + const res = loginReturnUrl.value + loginReturnUrl.value == null + return res + } + localStorage.removeItem(LOGIN_RETURN_URL_STORAGE) + loginReturnUrl.value == null + return storedUrl + } + + return { + setLoginReturnUrl, + getLoginReturnUrl + } +}) \ No newline at end of file diff --git a/src/types/ConfigSymbols.ts b/src/types/ConfigSymbols.ts index 3d00a04..0b9c80c 100644 --- a/src/types/ConfigSymbols.ts +++ b/src/types/ConfigSymbols.ts @@ -5,8 +5,11 @@ const apiBaseURL = Symbol() as InjectionKey const oidcProjectID = Symbol() as InjectionKey const oidc = Symbol() as InjectionKey +const LOGIN_RETURN_URL_STORAGE = "LOGIN_RETURN_URL_STORAGE" + export { apiBaseURL, oidcProjectID, - oidc + oidc, + LOGIN_RETURN_URL_STORAGE } \ No newline at end of file diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 93d3724..f0fe530 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -27,37 +27,37 @@ } } - diff --git a/src/views/PostLoginView.vue b/src/views/PostLoginView.vue new file mode 100644 index 0000000..3f9cbf3 --- /dev/null +++ b/src/views/PostLoginView.vue @@ -0,0 +1,10 @@ + + + diff --git a/src/views/TestView.vue b/src/views/TestView.vue index 2da0bb4..b5b51fd 100644 --- a/src/views/TestView.vue +++ b/src/views/TestView.vue @@ -1,6 +1,5 @@