Skip to content

Commit 624fff2

Browse files
author
Walker Leite
committed
fix(auth): only change router after account exists
1 parent e1df64d commit 624fff2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

template/client/store/modules/auth/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import router from '@/router';
77
export function syncToken({commit, dispatch}) {
88
if (loopback.token) {
99
commit('setAccessToken', loopback.token);
10-
dispatch('loadAccount', loopback.token.userId);
10+
return dispatch('loadAccount', loopback.token.userId);
1111
}
1212
}
1313

1414
/**
1515
* Sync router for auth
1616
*/
1717
export function syncRouter({state, dispatch}, myRouter) {
18-
dispatch('syncToken');
18+
const synced = dispatch('syncToken');
1919

2020
myRouter.beforeEach((to, from, next) => {
2121
if (to.matched.some(record => record.meta.requiresAuth)) {
@@ -29,7 +29,7 @@ export function syncRouter({state, dispatch}, myRouter) {
2929
name: 'login',
3030
});
3131
} else {
32-
next();
32+
synced.then(next);
3333
}
3434
} else {
3535
next(); // make sure to always call next()!

0 commit comments

Comments
 (0)