I am trying to set-up an auth-guard for a profile page. I am using Vue (2.0) with vue-router and Vuex for state. My backend is firebase, but I don't think that's imporant here? My auth-guard function seems unable to properly fetch the requiresAuth state.
This is my auth-guard function:
{
path: "/profile",
name: "Profile",
component: Profile,
meta: {
requiresAuth: true
}
}
];
const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes
});
router.beforeEach((to, from, next) => {
console.log('-----------ROUTE GUARD PROPS--------');
console.log(store.state.user.isAuthorized);
console.log(store.state.user);
console.log('----------- END ROUTE GUARD PROPS--------');
if (to.matched.some(record => record.meta.requiresAuth)) {
if (store.state.user.isAuthorized) {
next()
} else {
next("/Login")
}
} else {
next()
}
})
And the result in the browser console when changing pages is the following:
The issue here, to be clear, is why the console.log
contradicts the isAuthorized
in the print-out of the user
module's state
. For reference, my store has a user
and shared
module. The user
module has a state
with two members: user
and isAuthorized
. Hence the browser output.
Any ideas why these two conflict?
console.log(store.state.user.isAuthorized)
andconsole.log(store.state.user)
shows two different things in the console? – Hiwsconsole.log(store.state.user.isAuthorized)
appears to befalse
but theisAuthorized
within thestore.state.user
istrue
. I feel like these should be the same thing? – Paco