gothinkster / vue-realworld-example-app

An exemplary real-world application built with Vue.js, Vuex, axios and different other technologies. This is a good example to discover Vue for beginners.
https://vue-vuex-realworld.netlify.com
MIT License
4.07k stars 1.3k forks source link

checkAuth should also commit purgeAuth when an error is catched #159

Open AlexanderOpran opened 5 years ago

AlexanderOpran commented 5 years ago

https://github.com/gothinkster/vue-realworld-example-app/blob/e9edd6f6148cad07b68f32d2a770e2bc7e68af14/src/store/auth.module.js#L56-L69

As it currently stands, when the JWT token expires or is invalid the user will be permanently stuck in the isAuthenticated state. You can test it for yourselves by going to https://vue-vuex-realworld.netlify.com/, log in and then delete the token from local storage or alter it a bit and then either go to a new route or refresh the page and see what happens.

I think this is a pretty serious issue.

When the authentication check fails (401), we should also commit the purgeAuth mutation in order to clear the state.

AlexanderOpran commented 5 years ago

No one actually encountered this problem?

mkantautas commented 5 years ago

When the authentication check fails (401), we should also commit the purgeAuth mutation in order to clear the state.

^ Exactly what I've changed when building from this template. Because with the current repo state for e.g. when jwt token expires and your API starts sending you 401 (Unauthorized) - your front-end stays on the same page, rather than committing a purgAuth commit and pushing you to Login page.

thinh105 commented 4 years ago

thank guys to pointing out of this bug, I stuck in that 2 days