Skip to content

Multiple Request Pause is not working #248

@erdemsusam

Description

@erdemsusam

First of all thanks for this library.
Lib versions:

"axios": "^1.3.2",
"axios-auth-refresh": "^3.3.6",

First of all here is my configurationg:

 const refreshAuthLogic = async (failed) => {
    const tokenRefreshResponse = await HTTP.post('/auth/refresh', {
        refreshToken: authStore.refreshToken
    })
    try {
        console.log(failed);
        if (tokenRefreshResponse?.data?.accessToken) {
            console.log("Refresh successful")
            authStore.accessToken = tokenRefreshResponse.data.accessToken
            authStore.refreshToken = tokenRefreshResponse.data.refreshToken
            return Promise.resolve();
        } else {
            return Promise.reject("Token refresh failed")
        }

    } catch (error) {
        return Promise.reject(error);
    }
}

// Instantiate the interceptor
createAuthRefreshInterceptor(HTTP, refreshAuthLogic, {
    statusCodes: [401] // default: [ 401 ]
});

HTTP.interceptors.request.use(
    (config) => {
        const newDate = new Date();
        const dateString = newDate.toLocaleTimeString();
        console.log(dateString);
        const token = authStore.accessToken
        if (token && config.url !== "/auth/refresh") {
            config.headers["Authorization"] = 'Bearer ' + token;  // for Spring Boot back-end
        }

        return config
    },
    (error) => {
        return Promise.reject(error);
    }
);

My problem is that library's request interceptor is not pausing active requests if 401 is taken. Also refresh is triggered again.
This is how I call requests:

const flowReq = HTTP.get('/flows');
try {

  const response = await flowReq;
  this.flows = response.data
} catch (error) {
  console.log("error", error)
}

const projectReq = return HTTP.get('/projects/tree-select');
try {

  const response = await projectReq;
  this.projectsTree = response.data

  this.projects = this.projectsTree.map(p => ({
    projectName: p.label,
    projectCode: p.data
  }));
} catch (error) {
  console.log("error", error)
}

And axios instance is:

export const HTTP = axios.create({
    baseURL: 'http://localhost:8088/api',
    headers: {
        "Content-Type": "application/json",
    }
    //headers: authHeader()
});

As I review codes, my understanding is library pauses any request after first 401 reponse, then refresh is called. Then if refresh resolves, continues with paused requests, if refresh fail (with Pormise.reject) remaining requests canceled. I'm using Vue.
Any help is appreciated, thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions