Nuxt 2 - async middleware bugs first render of index.vue
Hello, I have an async middleware called check_session on the following path middleware/check_session.js
´´´
export default async function ({ app }) {
if (
process.server &&
app.$cookies.get('access_token') &&
app.$cookies.get('refresh_token') &&
app.$cookies.get('expires')
) {
return await app.$axios.get('/api/users/me', {
headers: { Authorization:
Bearer ${app.$cookies.get('access_token')}
},
params: {
fields: [
'id',
'first_name',
'last_name',
'email',
'avatar,avatar.',
'role.name',
'companies.companies_id.',
'last_projects_paginator',
'last_indicators_paginator'
]
}
}).then((response) => {
if (response.data.data.role && response.data.data.role.name && !['Administrator'].includes(response.data.data.role.name)) {
if (response?.data.data?.companies?.length > 0) {
console.log('setting company')
app.store.commit('session/signin/set_interface_company', response.data.data.companies[0].companies_id?.id)
// this.commit('session/signin/set_interface_company', this.formData.company)
} else {
console.log('no company')
}
}
app.store.commit('session/signin/init_session')
app.store.commit('session/profile/update_me', response.data.data, { root: true })
return true
}).catch((error) => {
return false
})
}
}´´´
The problem is when I execute "yarn dev" the app doesn't start properly, it keeps in infinite loop of loading
I have to comment/uncomment the middleware calling on layouts/default.vue to run properly the app, is there any chance you could help me to solve this?0 Replies