Open alexaandru opened 5 years ago
While we're at it, on my own code, I simplified that even further, a bit into absurd :D :
router.beforeEach((to, from, next) => {
if (!to.meta)
return next()
if (to.meta.title)
document.title = to.meta.title
if (!to.meta.auth || store.getters["auth/isAuthenticated"])
return next()
router.push({ name: "signIn" })
})
It is identical to the (fixed) function from the router behavior wise, but it would likely be quite confusing for beginners (and not only) which is why I did not proposed it. Just mentioned it for fun :)
I'm a big fan of early returns, I think that all those levels of indentation (and mental overhead) is what lead to this bug in the 1st place. But the return next()
is definitely in the gray area (at best) :)
I was unable to access the homepage while being authenticated, and it all boiled down to this: https://github.com/wolfeidau/cognito-vue-bootstrap/blob/master/src/router/index.js#L72-L76, I quote:
in other words, if
meta.auth
was notundefined
and it was also nottrue
, then we would be redirected to Dashboard. Can be quite confusing, especially for a newbie trying to get started.