Pin 8
Pin 8
NNuxt
Created by Pin 8 on 3/28/2024 in #❓・help
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?
1 replies
NNuxt
Created by Pin 8 on 6/17/2023 in #❓・help
Modifying code in a composable throws error 500 composable is not defined
Hi all, i'm writing a composable on a nuxt 3 module. *Problem When I compile the app for the first time the composable work pretty good, but when I change code inside composable and hot reload acts the app throws an error 500 saying that my composable is not defined. Then i need to restart the app compiling again and all works perfect again. * Minimal reproduction Here I provide a minimal reproduction to that error, you could try defining a variable or add/remove a console.log and you should see the error. https://stackblitz.com/edit/github-1hay52?file=composables%2FuseNetwork.js I also checked that is there a post in stackoverflow but no solutions was provided. https://stackoverflow.com/questions/75942987/nuxt-3-code-change-in-composable-generates-referenceerror/76497211?noredirect=1#comment134880834_76497211 Any ideas of what i'm doing wrong or missing?
3 replies