Skip to content

Instantly share code, notes, and snippets.

@alexey-kar
Created December 3, 2018 05:12
Show Gist options
  • Save alexey-kar/a3ca50fd46ecf0798a783e4759c7507f to your computer and use it in GitHub Desktop.
Save alexey-kar/a3ca50fd46ecf0798a783e4759c7507f to your computer and use it in GitHub Desktop.
localStorage onchange
// при изменении токена в одной вкладке, меняем во всех остальных
// на пример когда в одной вкладке пользователь разлогинился, разлогинится должно и в остальных вкладках
$(window).on('storage', function (e) {
if (e.originalEvent.key == 'token') {
let token = e.originalEvent.newValue;
window.axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
store.commit('LOGIN', {token});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment