0π
β
In general it should work like that:
- user enters login/pass
- vuex action
userLogin
fired userLogin
action sends data to server, server returns tokenuserLogin
action saves token to thelocalStorage
userLogin
commits mutationUSER_LOGIN
with token and/or user credentials
Then to make auto-login with saved token (after browser closing, etc)
- on the app start you should call
userLoginLocal
vuex action userLoginLocal
reads token fromlocalStorage
userLoginLocal
should validate token or/and send to server for validationuserLoginLocal
commits mutationUSER_LOGIN
with token and/or user credentials (if token is valid)
NOTES:
Mutation USER_LOGIN
makes isLoggedIn = true
π€Max Liashuk
Source:stackexchange.com