Skip to content

Instantly share code, notes, and snippets.

@pipethedev
Created June 18, 2020 10:53
Show Gist options
  • Select an option

  • Save pipethedev/86f6b8d93154dc25c12cfc2c9f26e694 to your computer and use it in GitHub Desktop.

Select an option

Save pipethedev/86f6b8d93154dc25c12cfc2c9f26e694 to your computer and use it in GitHub Desktop.
import store from '@/store'
import axios from 'axios'
store.subscribe((mutation) => {
switch(mutation.type){
case 'auth/SET_TOKEN':
if(mutation.payload){
axios.defaults.headers.common['Authorization'] = `Bearer ${mutation.payload}`
localStorage.setItem('token', mutation.payload)
}else{
axios.defaults.headers.common['Authorization'] = null
localStorage.removeItem('token')
}
break;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment