0

I use axios to refreshToken of Application, I do Task: Refresh-Token with axiosInstance.interceptors.response, at expiration time callback error will handle and return axiosInstance(originalConfig);

if (error.response.status === UNAUTHORIZED && !originalConfig._retry) {
  //! toggle flag: true
  originalConfig._retry = true;
  try {
    await store
      .dispatch(
        refreshToken({
          refreshToken: store.getState().auth.refreshToken,
        })
      )
      .unwrap();
    // return a request with config
    return axiosInstance(originalConfig);
  } catch (error) {
    // If Promise.reject(err) -> throw this error to handleSubmit
    Promise.reject(error.message);
  }
}

But with case when I use multer (package). All my test cases are completed as expected if not refreshed, and when the re-fresh is successful, the request (req.images) cannot send images to the backend. For example, send 3 pictures then req.images only accepts 3 empty objects [ { }, { }, { } ]. I think the problem is that before re-fresh Token, the first request has brought the values of mutler, by the time the re-freshToken is successful, the request has lost the values of multer.

//! @desc     Create a new Product
//! @route    POST /api/products
//! @access   Private: Admin

router.post(
  '/products/create',
  authenticate,
  isAdmin,
  uploadHandler, //! multer handler middleware here...
  validateSchema(createProductSchema),
  productController.createProduct
);

Help me return axiosInstance(originalConfig) with the value of multer with.

0 Answers0