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,15 +1,19 @@
<script setup> <script setup>
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
import { VNodeRenderer } from './VNodeRenderer'
import { layoutConfig } from '@layouts' import { layoutConfig } from '@layouts'
import { import {
VerticalNavGroup, VerticalNavGroup,
VerticalNavLink, VerticalNavLink,
VerticalNavSectionTitle, VerticalNavSectionTitle,
} from '@layouts/components' } from '@layouts/components'
import { useLayoutConfigStore } from '@layouts/stores/config' import { useLayoutConfigStore } from '@layouts/stores/config'
import { injectionKeyIsVerticalNavHovered } from '@layouts/symbols' 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({ const props = defineProps({
tag: { tag: {
type: null, type: null,
@ -51,7 +55,26 @@ Close overlay vertical nav when link is clicked
*/ */
const route = useRoute() 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) props.toggleIsOverlayNavActive(false)
}) })

View File

@ -48,12 +48,17 @@ export default createStore({
siteSetting: null, siteSetting: null,
showMessage: null, showMessage: null,
timeout: null, timeout: null,
checkLoginExpire:false
}, },
mutations: { mutations: {
setLoading(state, payload) { setLoading(state, payload) {
console.log('payload'); console.log('payload');
state.isLoading = payload state.isLoading = payload
}, },
setCheckLoginExpire(state, payload) {
console.log('payload');
state.checkLoginExpire = payload
},
setErrorMsg(state, payload) { setErrorMsg(state, payload) {
console.log('payload'); console.log('payload');
clearTimeout(state.timeout) clearTimeout(state.timeout)
@ -117,6 +122,9 @@ export default createStore({
async updateIsLoading({ commit }, payload) { async updateIsLoading({ commit }, payload) {
commit('setLoading', payload) commit('setLoading', payload)
}, },
async updateCheckToken({ commit }, payload) {
commit('setCheckLoginExpire', payload)
},
async patientList({ commit }, payload) { async patientList({ commit }, payload) {
commit('setLoading', true) commit('setLoading', true)
console.log(localStorage.getItem('admin_access_token')) console.log(localStorage.getItem('admin_access_token'))
@ -685,6 +693,27 @@ export default createStore({
console.error('Error:', error); 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: { getters: {
getIsLoading(state){ getIsLoading(state){
@ -738,5 +767,8 @@ export default createStore({
getSiteSetting(state){ getSiteSetting(state){
return state.siteSetting return state.siteSetting
}, },
getCheckLoginExpire(state){
return state.checkLoginExpire
},
} }
}) })