[Vuejs]-How to update navbar links after login in vuejs

1👍

Assuming you have a Vuex action for login, you could use something like this:

actions: {
  async login({ commit }, credentials) {
    const response = await axios.post(...); // use `credentials` to log in
    const token = response.data;
    commit('SET_TOKEN', token);
  }
},
mutations: {
  SET_TOKEN(state, token) {
    localStorage.setItem('userToken', token);  // <-- set the token in storage
    state.user = token; // <-- also set the token in state
  }
}

At the time you login, you set the token in storage, and also set the token to state.user.

👤Dan

Leave a comment