Horje
axios 401 unauthorized refresh token multipal request Code Example
axios 401 unauthorized refresh token multipal request
let refreshTokenPromise // this holds any in-progress token refresh requests

// I just moved this logic into its own function
const getRefreshToken = () => http.post('/token/refresh', {}, {
  withCredentials: true,
  headers: { 'X-CSRF-TOKEN': Vue.$cookies.get('csrf_refresh_token') }
}).then(() => Vue.$cookies.get('csrf_access_token'))

http.interceptors.response.use(r => r, error => {
  if (error.config && error.response && error.response.status === 401) {
    if (!refreshTokenPromise) { // check for an existing in-progress request
      // if nothing is in-progress, start a new refresh token request
      refreshTokenPromise = getRefreshToken().then(token => {
        refreshTokenPromise = null // clear state
        return token // resolve with the new token
      })
    }

    return refreshTokenPromise.then(token => {
      error.config.headers['X-CSRF-TOKEN'] = token
      return http.request(error.config)
    })
  }
  return Promise.reject(error)
})




Whatever

Related
Bloom (TV series) Code Example Bloom (TV series) Code Example
i b or p frames for biggest compression Code Example i b or p frames for biggest compression Code Example
set main file htaccess Code Example set main file htaccess Code Example
recargar cache edge shortcut Code Example recargar cache edge shortcut Code Example
vscode highlight code between brackets Code Example vscode highlight code between brackets Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7