Skip to content
Advertisement

vue-router beforeEach function does not return item which is updated

I’m stuck with a problem. So here is the scenario. I put an axios request which takes the access token from cookies on store. Then I committed a mutation to make true isLoggedIn variable. Then I access this variable from Navbar to change menu items. It works. But when I try to access isLoggedIn variable with getters in beforeEach function, it turns still false. But it is true on Navbar.

user/actions.js which I request to backend to for authentication.

JavaScript

user/mutations.js which I set user and isLoggedIn variables

JavaScript

Then I call that action func in beforeEach in router

JavaScript

If you need any other information please say, so I can share with you. Any help will be appreciated.

Advertisement

Answer

You are awaiting checkUser but it doesn’t return a promise. Change it to:

JavaScript

Alternatively, you could use async/await:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement