fix
This commit is contained in:
parent
31893255d2
commit
970a063bec
@ -1,15 +1,19 @@
|
||||
<script setup>
|
||||
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
|
||||
import { VNodeRenderer } from './VNodeRenderer'
|
||||
import { layoutConfig } from '@layouts'
|
||||
import {
|
||||
VerticalNavGroup,
|
||||
VerticalNavLink,
|
||||
VerticalNavSectionTitle,
|
||||
VerticalNavGroup,
|
||||
VerticalNavLink,
|
||||
VerticalNavSectionTitle,
|
||||
} from '@layouts/components'
|
||||
import { useLayoutConfigStore } from '@layouts/stores/config'
|
||||
import { injectionKeyIsVerticalNavHovered } from '@layouts/symbols'
|
||||
|
||||
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
|
||||
import { useStore } from 'vuex'
|
||||
import { VNodeRenderer } from './VNodeRenderer'
|
||||
const store = useStore();
|
||||
const router = useRouter()
|
||||
const ability = useAbility()
|
||||
const userData = useCookie('userData')
|
||||
const props = defineProps({
|
||||
tag: {
|
||||
type: null,
|
||||
@ -51,7 +55,26 @@ Close overlay vertical nav when link is clicked
|
||||
*/
|
||||
const route = useRoute()
|
||||
|
||||
watch(() => route.name, () => {
|
||||
watch(() => route.name, async () => {
|
||||
console.log('name=====')
|
||||
|
||||
await store.dispatch('checkLogin')
|
||||
const isLoggedIn = await store.getters.getCheckLoginExpire
|
||||
console.log('check login', isLoggedIn)
|
||||
|
||||
// Add additional logic or redirection based on login status if needed
|
||||
if (isLoggedIn) {
|
||||
await store.dispatch('updateCheckToken',false)
|
||||
|
||||
// Redirect to login page or perform any other action
|
||||
useCookie('accessToken').value = null
|
||||
|
||||
localStorage.removeItem('admin_access_token');
|
||||
useCookie('userAbilityRules').value = null
|
||||
ability.update([])
|
||||
router.push({ name: 'login' })
|
||||
}
|
||||
|
||||
props.toggleIsOverlayNavActive(false)
|
||||
})
|
||||
|
||||
|
@ -48,12 +48,17 @@ export default createStore({
|
||||
siteSetting: null,
|
||||
showMessage: null,
|
||||
timeout: null,
|
||||
checkLoginExpire:false
|
||||
},
|
||||
mutations: {
|
||||
setLoading(state, payload) {
|
||||
console.log('payload');
|
||||
state.isLoading = payload
|
||||
},
|
||||
setCheckLoginExpire(state, payload) {
|
||||
console.log('payload');
|
||||
state.checkLoginExpire = payload
|
||||
},
|
||||
setErrorMsg(state, payload) {
|
||||
console.log('payload');
|
||||
clearTimeout(state.timeout)
|
||||
@ -117,6 +122,9 @@ export default createStore({
|
||||
async updateIsLoading({ commit }, payload) {
|
||||
commit('setLoading', payload)
|
||||
},
|
||||
async updateCheckToken({ commit }, payload) {
|
||||
commit('setCheckLoginExpire', payload)
|
||||
},
|
||||
async patientList({ commit }, payload) {
|
||||
commit('setLoading', true)
|
||||
console.log(localStorage.getItem('admin_access_token'))
|
||||
@ -685,6 +693,27 @@ export default createStore({
|
||||
console.error('Error:', error);
|
||||
});
|
||||
},
|
||||
async checkLogin({ commit }, payload) {
|
||||
//commit('setLoading', true)
|
||||
|
||||
await axios.post(ADMIN_LOGIN_DETAIL, {}, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('admin_access_token')}`,
|
||||
}
|
||||
}) .then(response => {
|
||||
//commit('setLoading', false)
|
||||
console.log('Response:', response.data);
|
||||
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
//commit('setLoading', false)
|
||||
console.error('Error:', error);
|
||||
if (error.response && error.response.status === 401 && error.response.data.error === 'Token has expired') {
|
||||
commit('setCheckLoginExpire', true)
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
getIsLoading(state){
|
||||
@ -738,5 +767,8 @@ export default createStore({
|
||||
getSiteSetting(state){
|
||||
return state.siteSetting
|
||||
},
|
||||
getCheckLoginExpire(state){
|
||||
return state.checkLoginExpire
|
||||
},
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user