I am currently facing an issue with accessing the authenticated user in my Vuex store within my router.js file.
{
path: '/admin/login',
name: 'admin-login',
component: AdminLogin,
beforeEnter(to, from, next) {
console.log(store.state.user);
if(store.getters.user) {
// check if an agency is trying to log in as admin
if (!store.getters.user.attributes['custom:role_id'] === 1) {
next({ name: 'agency-dashboard', params: { agency: store.getters.user.attributes['custom:agency_id'] } });
} else {
next({ name: 'admin-dashboard' });
}
} else {
next();
}
}
}
Upon using console.log(store.getters)
, I can see all properties in state, including the user object.
However, when I attempt to access console.log(store.getters.user)
, although it exists in my store.js, it simply returns false
, which is the default state of my user object upon page load.
The question remains - why is the user object visible through state.getters
but not through state.getters.user
?