Handle socket re-authentication, fix socket toast to be re-usable, socket cleanup

This commit is contained in:
advplyr 2025-07-06 11:07:01 -05:00
parent a24dae5262
commit e201247d69
5 changed files with 66 additions and 16 deletions

View file

@ -1,4 +1,4 @@
export default function ({ $axios, store, $config, app }) {
export default function ({ $axios, store, $root, app }) {
// Track if we're currently refreshing to prevent multiple refresh attempts
let isRefreshing = false
let failedQueue = []
@ -82,6 +82,11 @@ export default function ({ $axios, store, $config, app }) {
// Update the token in store and localStorage
store.commit('user/setUser', response.user)
// Emit event used to re-authenticate socket in default.vue since $root is not available here
if (app.$eventBus) {
app.$eventBus.$emit('token_refreshed', newAccessToken)
}
// Update the original request with new token
if (!originalRequest.headers) {
originalRequest.headers = {}