Last active
June 21, 2021 19:05
-
-
Save teyfix/c89cfd055a486930cfe431dc37d9d1ce to your computer and use it in GitHub Desktop.
vuex - logging user in with an action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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