2๐
โ
You can access the store. There is no problem with that as you are importing it.
The problem is with how you are accessing state.loggedInUser
. You might be using modules in your store and loggedInUser
might belong to a module. So to access it you need to refer to the module name that loggedInUser
belongs to like this:
if (store.state.moduleName.loggedInUser) {
? console.log("You are logged in :) Go to requested page ")
next()
}
Replace moduleName
with the name of the module loggedInUser
belongs to.
๐คVamsi Krishna
0๐
I was able to achieve this in a recent app by changing store.state.loggedInUser
for store.getters.loggedInUser
.
Essentially telling it to call the getter method directly instead of a mapping to the method through the state.
๐คMartin Calvert
Source:stackexchange.com