I use Pinia in a Quasar project.
When the code is according the doc from pinia, it creates a warning:
import {useAuthStore} from "stores/auth-store";
import { useRouter } from 'vue-router'
const router = useRouter()
const beforeEach = ((to, from, next) => {
const store = useAuthStore()
if (to.meta.needsAuth) {
if (store.authenticated) {
next()
}
else {
router.push('/')
}
} else {
next()
}
})
export default beforeEach
Warning:
[Vue warn]: inject() can only be used inside setup() or functional components.
I followed the doc from Pinia: https://pinia.vuejs.org/core-concepts/outside-component-usage.html#single-page-applications
If I set const store = useAuthStore() before the const store = useAuthStore() there is an error.
How do I have to modify the code to avoid the warning?