Route Authentication in Boot store undefined when using Pinia? #9268
-
|
Hi I'm using Pinia and try the Route Authentication, However store is undefined? export default boot(({ router, store }) => {
router.beforeEach((to, from, next) => {
// Now you need to add your authentication logic here, like calling an API endpoint
console.log('store', store) // undefined
next()
})
})Here's my Pinia setup in Boot also import { boot } from 'quasar/wrappers';
import { createPinia } from 'pinia'
const pinia = createPinia()
export default boot(({app}) => {
app.use(pinia)
console.log('Pinia was created', pinia)
app.config.globalProperties.$pinia = pinia
});
export { pinia } |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
Just tried your router boot code/file and it consoled the store object just fine. Could you post the output of 'quasar info' ? |
Beta Was this translation helpful? Give feedback.
-
|
You probably did not select Vuex (store) when creating your project with Quasar CLI. If I remember correctly Quasar checks for a store folder when bundling and if it exists it adds |
Beta Was this translation helpful? Give feedback.
-
|
The |
Beta Was this translation helpful? Give feedback.
The
storeis supplied only when using the Vuex one (so you have the /src/store folder).In your case, you are creating Pinia in a boot file and correctly exporting the store. So wherever you need it, just import it from the boot file. Example:
import { pinia } from 'boot/<your-pinia-boot-file>'. Just make sure that the pinia boot file is placed to run before all others that import from it.