From d8d7d61fca1be903bec1ac6e9b03abed6ea39bae Mon Sep 17 00:00:00 2001 From: Abizrh Date: Wed, 13 Aug 2025 13:17:21 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20enhance=20(auth):=20clear=20store?= =?UTF-8?q?=20on=20401=20and=20redirect=20to=20/401?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/flow/patient/list.vue | 1 - app/components/pub/base/error.vue | 3 ++- app/composables/useXfetch.ts | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/components/flow/patient/list.vue b/app/components/flow/patient/list.vue index 8537ce3b..82c23eb5 100644 --- a/app/components/flow/patient/list.vue +++ b/app/components/flow/patient/list.vue @@ -6,7 +6,6 @@ import { Calendar, Hospital, UserCheck, UsersRound } from 'lucide-vue-next' const data = ref([]) const refSearchNav: RefSearchNav = { - onClick: () => { // open filter modal }, diff --git a/app/components/pub/base/error.vue b/app/components/pub/base/error.vue index c1ebc354..7f7bc4ea 100644 --- a/app/components/pub/base/error.vue +++ b/app/components/pub/base/error.vue @@ -43,7 +43,8 @@ const router = useRouter()
- + +
diff --git a/app/composables/useXfetch.ts b/app/composables/useXfetch.ts index 24518c18..e4e4c3ef 100644 --- a/app/composables/useXfetch.ts +++ b/app/composables/useXfetch.ts @@ -55,6 +55,10 @@ export async function xfetch( const status = fetchError.response?.status || 500 const resJson = fetchError.data + if (status === 401 && import.meta.client) { + clearStore() + } + if (resJson?.errors) { errors = resJson.errors } else if (resJson?.code && resJson?.message) { @@ -68,3 +72,10 @@ export async function xfetch( return { success, status_code: status, body, errors, error, message } } } + +function clearStore() { + const { $pinia } = useNuxtApp() + const userStore = useUserStore($pinia) + userStore.logout() + navigateTo('/401') +}