Skip to content

Problem using axios-auth-refresh with react-query #258

@Arsh1a

Description

@Arsh1a

So if the Function that calls the refresh authorization fails, React-query isLoading will always be true.

Here is my code:

import axios from "axios";
import createAuthRefreshInterceptor from "axios-auth-refresh";

const axiosInstance = axios.create({
  baseURL: process.env.NEXT_PUBLIC_API_URI,
  withCredentials: true,
});

createAuthRefreshInterceptor(axiosInstance, (failedRequest) =>
  axiosInstance.get("/auth/access-token").then((res) => {
    return Promise.resolve();
  })
);

export const getData = async (url: string, withCredentials?: boolean) => {
  return await axiosInstance.get(process.env.NEXT_PUBLIC_API_URI + url);
};``

And this is how i use it using react-query

const { data: userData, isLoading,isError } = useQuery({
    queryKey: ["auth"],
    queryFn: () => getData("/users/me", true),
});

If I console log isLoading, it will be always true even tho isError is true, so the ```isLoading`` `should be false.

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