Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Integrate Auth tokens into buildRequest function in store/lib/helpers.js #119

Open
aeksco opened this issue Apr 21, 2018 · 0 comments
Open
Labels

Comments

@aeksco
Copy link
Member

aeksco commented Apr 21, 2018

This can be done with the following snippet:

import store from '@/store'
...
function buildRequest () {
  ...
  let token = store.getters['auth/token']
  if (token) { requestHeaders['Authorization'] = `Bearer ${token}` }
  ...
}

Next, remove the following from all associated Vuex store actions, such that this:

  fetchCollection: ({ commit, rootGetters }) => {
    commit('fetching', true)

    let api = API_ROOT + '/present/me'

    $GET(api, { token: rootGetters['auth/token'] })
    .then((json) => {
      commit('collection', json)
      commit('fetching', false)
    })
    .catch((err) => {
      commit('fetching', false)
      throw err
    })
  },

Becomes this:

  fetchCollection: ({ commit }) => {
    commit('fetching', true)

    let api = API_ROOT + '/present/me'

    $GET(api)
    .then((json) => {
      commit('collection', json)
      commit('fetching', false)
    })
    .catch((err) => {
      commit('fetching', false)
      throw err
    })
  },

Make that change in the following files:

  • src/store/achievement/actions.js
  • src/store/attendance/actions.js
  • src/store/blog/actions.js
  • src/store/classyear/actions.js
  • src/store/project/actions.js
  • src/store/smallgroup/actions.js
  • src/store/user/actions.js
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants