Flyrell / axios-auth-refresh

Library that helps you implement automatic refresh of authorization via axios interceptors. You can easily intercept the original request when it fails, refresh the authorization and continue with the original request, without user even noticing.
MIT License
1.06k stars 91 forks source link

response.use will enter twice when retry #187

Closed luchanan closed 2 years ago

luchanan commented 2 years ago

hi, i has a question:

this code will enter twice when refresh token finished.

if i dont change code Promise.resolve(res) will not entry again.

const service = axios.create({
  timeout: 5000,
})
service.interceptors.response.use(
  (response: AxiosResponse<any>) => {
    // first response: {config: {}, data: {code: '200', data: []}, status: 200, ....}
   //  second response: {code: '0', data: []}
    let res = response.data
    if (+res.code === 200) {
     // here will return {code: '0', data: []}
      return Promise.resolve(res)
    }

now my solution is:

service.interceptors.response.use(
  (response: AxiosResponse<any>) => {
    let res = response.data
    if (!response.config) {
     // temp solution
      res = response
    }
    if (+res.code === 200) {
      return Promise.resolve(res)
    }

what can i avoid this? thanks

Flyrell commented 2 years ago

Please, use StackOverflow or Github's Discussions. Thank you.

ValeriaVasilieva commented 12 months ago

same issue