[Vuejs]-How to create redirect after auth user, vue.js?

0πŸ‘

βœ…

In general it should work like that:

  • user enters login/pass
  • vuex action userLogin fired
  • userLogin action sends data to server, server returns token
  • userLogin action saves token to the localStorage
  • userLogin commits mutation USER_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 from localStorage
  • userLoginLocal should validate token or/and send to server for validation
  • userLoginLocal commits mutation USER_LOGIN with token and/or user credentials (if token is valid)

NOTES:
Mutation USER_LOGIN makes isLoggedIn = true

πŸ‘€Max Liashuk

Leave a comment