Reputation: 734
I have a function that lets me delete an account when a function deleteAccount is called. I want the user to be logged out straight after deleteAccount is returned from vuex store. Now I found a workaround for this by using setTimeout, however I don't feel as though this is really an optimal of doing it. Can someone kindly suggest a more optimal solution for this?
deleteAccount component
logout: function () {
this.$store.commit(SET_LOGOUT);
this.$store.commit(RESET_BASIC_MODAL_DATA);
this.$router.push({name: ROUTE_NAMES_AUTH.LOGIN});
},
deleteAccount: function () {
setTimeout(this.logout, 50);
return this.$store.dispatch(DELETE_USER_ACCOUNT);
},
Upvotes: 0
Views: 376
Reputation: 747
vuex actions return a promise, you can use then
or await
:
this.$store.dispatch(DELETE_USER_ACCOUNT).then(logout)
// or
deleteAccount: async function () {
await this.$store.dispatch(DELETE_USER_ACCOUNT)
logout()
}
Upvotes: 2