Created
December 3, 2018 05:12
-
-
Save alexey-kar/a3ca50fd46ecf0798a783e4759c7507f to your computer and use it in GitHub Desktop.
localStorage onchange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// при изменении токена в одной вкладке, меняем во всех остальных | |
// на пример когда в одной вкладке пользователь разлогинился, разлогинится должно и в остальных вкладках | |
$(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