From fa595b965fa21c5506527292d3669c9b63ff3899 Mon Sep 17 00:00:00 2001 From: Maikiwi <74925636+maikirakiwi@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:00:51 -0700 Subject: [PATCH 1/7] =?UTF-8?q?emove=20token=20from=20Window.localStorage?= =?UTF-8?q?=E2=80=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui/src/hooks/useAuth.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webui/src/hooks/useAuth.ts b/webui/src/hooks/useAuth.ts index e0bcc958..01814468 100644 --- a/webui/src/hooks/useAuth.ts +++ b/webui/src/hooks/useAuth.ts @@ -10,7 +10,7 @@ export const useAuth = createSharedComposable(() => { password: '', }); - const isLogin = computed(() => auth.value !== ''); + const isLogin = computed(() => auth.value === '1'); function clearUser() { user.username = ''; @@ -39,7 +39,7 @@ export const useAuth = createSharedComposable(() => { }); onResult((res) => { - auth.value = `${res.token_type} ${res.access_token}`; + auth.value = `1`; clearUser(); }); @@ -76,7 +76,7 @@ export const useAuth = createSharedComposable(() => { ); onRefreshResult((res) => { - auth.value = `${res.token_type} ${res.access_token}`; + auth.value = `1`; }); function update() { @@ -90,7 +90,7 @@ export const useAuth = createSharedComposable(() => { onResult((res) => { if (res.message === 'update success') { - auth.value = `${res.token_type} ${res.access_token}`; + auth.value = ``; clearUser(); } else { user.password = ''; From d1bcce05dc927ba847e427957fab388c8b8c2ebd Mon Sep 17 00:00:00 2001 From: Maikiwi <74925636+maikirakiwi@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:59:45 -0700 Subject: [PATCH 2/7] condense to isloggedin --- webui/src/App.vue | 4 ++-- webui/src/hooks/useAuth.ts | 14 ++++++-------- webui/src/router/index.ts | 8 ++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/webui/src/App.vue b/webui/src/App.vue index af1f79a4..edf84327 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -11,8 +11,8 @@ const theme: GlobalThemeOverrides = { }, }; -const { refresh, isLogin } = useAuth(); -if (isLogin.value) { +const { refresh, isLoggedin } = useAuth(); +if (isLoggedin.value === true) { refresh(); } diff --git a/webui/src/hooks/useAuth.ts b/webui/src/hooks/useAuth.ts index 01814468..fb3ce35d 100644 --- a/webui/src/hooks/useAuth.ts +++ b/webui/src/hooks/useAuth.ts @@ -2,7 +2,7 @@ import type { User } from '#/auth'; import type { ApiError } from '#/api'; export const useAuth = createSharedComposable(() => { - const auth = useLocalStorage('auth', ''); + const isLoggedin = useLocalStorage('isLoggedin', false); const message = useMessage(); const user = reactive({ @@ -10,7 +10,6 @@ export const useAuth = createSharedComposable(() => { password: '', }); - const isLogin = computed(() => auth.value === '1'); function clearUser() { user.username = ''; @@ -39,7 +38,7 @@ export const useAuth = createSharedComposable(() => { }); onResult((res) => { - auth.value = `1`; + isLoggedin.value = true; clearUser(); }); @@ -68,7 +67,7 @@ export const useAuth = createSharedComposable(() => { onLogoutResult(() => { clearUser(); - auth.value = ''; + isLoggedin.value = false; }); const { execute: refresh, onResult: onRefreshResult } = useApi( @@ -76,7 +75,7 @@ export const useAuth = createSharedComposable(() => { ); onRefreshResult((res) => { - auth.value = `1`; + isLoggedin.value = true; }); function update() { @@ -90,7 +89,7 @@ export const useAuth = createSharedComposable(() => { onResult((res) => { if (res.message === 'update success') { - auth.value = ``; + isLoggedin.value = false; clearUser(); } else { user.password = ''; @@ -107,9 +106,8 @@ export const useAuth = createSharedComposable(() => { } return { - auth, + isLoggedin, user, - isLogin, login, logout, diff --git a/webui/src/router/index.ts b/webui/src/router/index.ts index 8a9ff55a..4e620998 100644 --- a/webui/src/router/index.ts +++ b/webui/src/router/index.ts @@ -5,14 +5,14 @@ const router = createRouter({ }); router.beforeEach((to) => { - const { isLogin } = useAuth(); + const { isLoggedin } = useAuth(); const { type, url } = storeToRefs(usePlayerStore()); - if (!isLogin.value && to.path !== '/login') { + if (!isLoggedin.value && to.path !== '/login') { return { name: 'Login' }; } - if (isLogin.value && to.path === '/login') { + if (isLoggedin.value && to.path === '/login') { return { name: 'Index' }; } @@ -21,7 +21,7 @@ router.beforeEach((to) => { return false; } - watch(isLogin, (val) => { + watch(isLoggedin, (val) => { if (to.path === '/login' && val) { router.replace({ name: 'Index' }); } From 6964ac9b97979942ec58a17deea93962d6bc83d1 Mon Sep 17 00:00:00 2001 From: Maikiwi <74925636+maikirakiwi@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:13:50 -0700 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E4=BA=86=E4=B8=80=E4=BA=9Bfeature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui/src/hooks/useAppInfo.ts | 4 ++-- webui/src/store/log.ts | 4 ++-- webui/src/utils/axios.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/webui/src/hooks/useAppInfo.ts b/webui/src/hooks/useAppInfo.ts index 6bbba953..0c533d03 100644 --- a/webui/src/hooks/useAppInfo.ts +++ b/webui/src/hooks/useAppInfo.ts @@ -1,5 +1,5 @@ export const useAppInfo = createSharedComposable(() => { - const { auth } = useAuth(); + const { isLoggedin } = useAuth(); const running = ref(false); const version = ref(''); @@ -11,7 +11,7 @@ export const useAppInfo = createSharedComposable(() => { version.value = res.version; }); - if (auth.value !== '') { + if (isLoggedin.value !== false) { execute(); } } diff --git a/webui/src/store/log.ts b/webui/src/store/log.ts index b1fe8566..d08a9eaf 100644 --- a/webui/src/store/log.ts +++ b/webui/src/store/log.ts @@ -1,6 +1,6 @@ export const useLogStore = defineStore('log', () => { const log = ref(''); - const { auth } = useAuth(); + const { isLoggedin } = useAuth(); const message = useMessage(); function get() { @@ -10,7 +10,7 @@ export const useLogStore = defineStore('log', () => { log.value = value; }); - if (auth.value !== '') { + if (isLoggedin.value !== false) { execute(); } } diff --git a/webui/src/utils/axios.ts b/webui/src/utils/axios.ts index 4aab6a80..01de5600 100644 --- a/webui/src/utils/axios.ts +++ b/webui/src/utils/axios.ts @@ -35,8 +35,8 @@ axios.interceptors.response.use( /** token 过期 */ if (error.status === 401) { - const { auth } = useAuth(); - auth.value = ''; + const { isLoggedin } = useAuth(); + isLoggedin.value = false; } /** 执行失败 */ From 66eb5147c08eaeb341f289241b61d7b6e7a6c7b8 Mon Sep 17 00:00:00 2001 From: Maikiwi <74925636+maikirakiwi@users.noreply.github.com> Date: Mon, 16 Oct 2023 00:45:27 -0700 Subject: [PATCH 4/7] pr requested changes --- webui/src/App.vue | 6 +++--- webui/src/hooks/useAppInfo.ts | 4 +--- webui/src/hooks/useAuth.ts | 1 - webui/src/store/log.ts | 4 +--- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/webui/src/App.vue b/webui/src/App.vue index edf84327..7a5da898 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -12,9 +12,9 @@ const theme: GlobalThemeOverrides = { }; const { refresh, isLoggedin } = useAuth(); -if (isLoggedin.value === true) { - refresh(); -} + +refresh(); +