File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed
generator/templates/Default/src/store/modules Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 11import router from '../../router' ;
22
3+ const initialState = ( { token : null } ) ;
4+
35export 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} ;
You can’t perform that action at this time.
0 commit comments