Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Cannot access homepage while authenticated #21

Open
alexaandru opened this issue Oct 3, 2018 · 2 comments
Open

Cannot access homepage while authenticated #21

alexaandru opened this issue Oct 3, 2018 · 2 comments

Comments

@alexaandru
Copy link
Contributor

alexaandru commented Oct 3, 2018

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:

    if (to.meta && to.meta.auth !== undefined) {
        if (to.meta.auth) {
          // ...
        }
        // otherwise are we already authenticated?
        if (store.getters['auth/isAuthenticated']) {
            // yes we are, so off to dashboard
            router.push({ name: 'dashboard' })
            return
        }
        // ...
    }

in other words, if meta.auth was not undefined and it was also not true, then we would be redirected to Dashboard. Can be quite confusing, especially for a newbie trying to get started.

@alexaandru
Copy link
Contributor Author

#22 should fix this.

@alexaandru
Copy link
Contributor Author

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) :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant