[Vuejs]-Latest jwt token is not updated in vue

0👍

You clearly have to use Vuex for this task.

You are sending your token from root to child components – are you going to add this property to every component that needs it? That’s why Vuex is needed. It synchronises the data across whole application.

Move all your token receiving logic to Vuex module, like this:

  1. Create token in Vuex state with initial value fetched from storage
  2. Create mutation that will set token to storage and set token in state
  3. Create action that will call API and pass token to mutation
  4. Create getter to use this token from Vuex

This is also explained here: https://scotch.io/tutorials/handling-authentication-in-vue-using-vuex

Leave a comment