Skip to content

Commit 19eb3e9

Browse files
author
Walker Leite
committed
fix(auth): only change route after login
1 parent 624fff2 commit 19eb3e9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ import router from '@/router';
44
/**
55
* Sync loopback token with current state
66
*/
7-
export function syncToken({commit, dispatch}) {
7+
export function syncToken({commit}) {
88
if (loopback.token) {
99
commit('setAccessToken', loopback.token);
10-
return dispatch('loadAccount', loopback.token.userId);
1110
}
1211
}
1312

1413
/**
1514
* Sync router for auth
1615
*/
1716
export function syncRouter({state, dispatch}, myRouter) {
18-
const synced = dispatch('syncToken');
17+
dispatch('syncToken');
1918

2019
myRouter.beforeEach((to, from, next) => {
2120
if (to.matched.some(record => record.meta.requiresAuth)) {
@@ -29,7 +28,8 @@ export function syncRouter({state, dispatch}, myRouter) {
2928
name: 'login',
3029
});
3130
} else {
32-
synced.then(next);
31+
dispatch('loadAccount', state.access_token.userId)
32+
.then(next);
3333
}
3434
} else {
3535
next(); // make sure to always call next()!

0 commit comments

Comments
 (0)