This commit is contained in:
nasir@endelospay.com 2024-06-06 22:48:39 +05:00
parent 31893255d2
commit 970a063bec
2 changed files with 62 additions and 7 deletions

View File

@ -1,6 +1,4 @@
<script setup>
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
import { VNodeRenderer } from './VNodeRenderer'
import { layoutConfig } from '@layouts'
import {
VerticalNavGroup,
@ -9,7 +7,13 @@ import {
} 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)
})

View File

@ -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
},
}
})