- add AuthRefreshProvider to refresh auth tokens every 5 minutes

- pull the latest crowdin language artifacts
This commit is contained in:
Amruth Pillai
2024-05-10 10:52:35 +02:00
parent b0d26e3230
commit c1a58118c2
34 changed files with 5798 additions and 4007 deletions

View File

@ -4,7 +4,7 @@ import _axios from "axios";
import createAuthRefreshInterceptor from "axios-auth-refresh";
import { redirect } from "react-router-dom";
import { refresh } from "@/client/services/auth";
import { refreshToken } from "@/client/services/auth";
import { USER_KEY } from "../constants/query-keys";
import { toast } from "../hooks/use-toast";
@ -40,18 +40,12 @@ axios.interceptors.response.use(
const axiosForRefresh = _axios.create({ baseURL: "/api", withCredentials: true });
// Interceptor to handle expired access token errors
const handleAuthError = async () => {
await refresh(axiosForRefresh);
await Promise.resolve();
};
const handleAuthError = () => refreshToken(axiosForRefresh);
// Interceptor to handle expired refresh token errors
const handleRefreshError = async () => {
void queryClient.invalidateQueries({ queryKey: USER_KEY });
await queryClient.invalidateQueries({ queryKey: USER_KEY });
redirect("/auth/login");
await Promise.resolve();
};
// Intercept responses to check for 401 and 403 errors, refresh token and retry the request