⚡ enhance (auth): clear store on 401 and redirect to /401
This commit is contained in:
No files matched your search
@@ -6,7 +6,6 @@ import { Calendar, Hospital, UserCheck, UsersRound } from 'lucide-vue-next'
|
|||||||
const data = ref([])
|
const data = ref([])
|
||||||
|
|
||||||
const refSearchNav: RefSearchNav = {
|
const refSearchNav: RefSearchNav = {
|
||||||
|
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
// open filter modal
|
// open filter modal
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ const router = useRouter()
|
|||||||
</template>
|
</template>
|
||||||
<div class="mt-6 flex gap-4">
|
<div class="mt-6 flex gap-4">
|
||||||
<Button variant="outline" @click="router.back()"> Kembali </Button>
|
<Button variant="outline" @click="router.back()"> Kembali </Button>
|
||||||
<Button @click="router.push('/')"> Kembali Ke Dashboard </Button>
|
<Button v-if="statusCode === 401" @click="router.push('/auth/login')">Login</Button>
|
||||||
|
<Button v-else @click="router.push('/')">Kembali ke Dashboard</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ export async function xfetch(
|
|||||||
const status = fetchError.response?.status || 500
|
const status = fetchError.response?.status || 500
|
||||||
const resJson = fetchError.data
|
const resJson = fetchError.data
|
||||||
|
|
||||||
|
if (status === 401 && import.meta.client) {
|
||||||
|
clearStore()
|
||||||
|
}
|
||||||
|
|
||||||
if (resJson?.errors) {
|
if (resJson?.errors) {
|
||||||
errors = resJson.errors
|
errors = resJson.errors
|
||||||
} else if (resJson?.code && resJson?.message) {
|
} else if (resJson?.code && resJson?.message) {
|
||||||
@@ -68,3 +72,10 @@ export async function xfetch(
|
|||||||
return { success, status_code: status, body, errors, error, message }
|
return { success, status_code: status, body, errors, error, message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearStore() {
|
||||||
|
const { $pinia } = useNuxtApp()
|
||||||
|
const userStore = useUserStore($pinia)
|
||||||
|
userStore.logout()
|
||||||
|
navigateTo('/401')
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user