can't use pinia on beforeEach #14957
Answered
by
yusufkandemir
Isnaeni2003
asked this question in
General - Components / Directives / etc
-
i have a problem , i want to create login in quasar and use pinia parameter (isAuth = false) in index.js file ( for beforeEach) but pinia can't work in that file and i get error in browser like this
full code :
thanks |
Beta Was this translation helpful? Give feedback.
Answered by
yusufkandemir
Nov 22, 2022
Replies: 1 comment
-
You can use a boot file where you have access to the router, to the store, and more. import { boot } from 'quasar/wrappers';
import { useAuthStore } from 'stores/auth';
export default boot(({ router, store }) => {
// the store parameter is optional for non-SSR apps
const authStore = useAuthStore(store);
router.beforeEach((to, from) => {
if (authStore.user == null && to.path !== "/login" ) {
return { path: "/login" }
}
if (authStore.user !== null && to.path === "/login") {
return { path: "/" }
}
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
yusufkandemir
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use a boot file where you have access to the router, to the store, and more.