Skip to content

Commit cc2f133

Browse files
committed
🐛 hard reset auth store on logout
1 parent bb4521b commit cc2f133

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import router from '../../router';
22

3+
const initialState = ({ token: null });
4+
35
export default {
46
namespaced: true,
5-
state: {
6-
token: '',
7-
},
7+
state: initialState,
88
mutations: {
99
setAuthorisationToken(state, token) {
10-
state.token = token;
10+
Object.assign(state, { token });
11+
},
12+
resetAuthorisation(state) {
13+
Object.keys(state).forEach((key) => delete state[key]);
14+
Object.assign(state, initialState);
1115
},
1216
},
1317
actions: {
14-
logout(context) {
15-
context.commit('setAuthorisationToken', '');
16-
17-
router.push({
18-
name: 'login',
19-
});
18+
logout({ commit }) {
19+
commit('resetAuthorisation');
20+
router.push({ name: 'login' });
2021
},
2122
},
2223
getters: {
23-
isLoggedIn: state => !!state.token.length,
24+
isLoggedIn: state => !!state.token,
2425
},
2526
};

0 commit comments

Comments
 (0)