Skip to content

Instantly share code, notes, and snippets.

@teyfix
Last active June 21, 2021 19:05
Show Gist options
  • Select an option

  • Save teyfix/c89cfd055a486930cfe431dc37d9d1ce to your computer and use it in GitHub Desktop.

Select an option

Save teyfix/c89cfd055a486930cfe431dc37d9d1ce to your computer and use it in GitHub Desktop.
vuex - logging user in with an action
const store = Vuex.Store({
state: {
user: null,
},
mutations: {
setUser(state, user) {
state.user = user;
},
},
actions: {
async login(state, payload) {
const session = await authorize(payload.username, payload.password);
await store.commit('setUser', session.user);
return session.user;
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment