Skip to content

Commit

Permalink
fix(auth): only change router after account exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Walker Leite committed Mar 2, 2018
1 parent e1df64d commit 624fff2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions template/client/store/modules/auth/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import router from '@/router';
export function syncToken({commit, dispatch}) {
if (loopback.token) {
commit('setAccessToken', loopback.token);
dispatch('loadAccount', loopback.token.userId);
return dispatch('loadAccount', loopback.token.userId);
}
}

/**
* Sync router for auth
*/
export function syncRouter({state, dispatch}, myRouter) {
dispatch('syncToken');
const synced = dispatch('syncToken');

myRouter.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
Expand All @@ -29,7 +29,7 @@ export function syncRouter({state, dispatch}, myRouter) {
name: 'login',
});
} else {
next();
synced.then(next);
}
} else {
next(); // make sure to always call next()!
Expand Down

0 comments on commit 624fff2

Please sign in to comment.