diff --git a/src/Providers/AuthUserProvider.tsx b/src/Providers/AuthUserProvider.tsx index 2f754c56bda..1fd23af719e 100644 --- a/src/Providers/AuthUserProvider.tsx +++ b/src/Providers/AuthUserProvider.tsx @@ -4,7 +4,7 @@ import Loading from "../Components/Common/Loading"; import routes from "../Redux/api"; import useQuery from "../Utils/request/useQuery"; import { LocalStorageKeys } from "../Common/constants"; -import axios from "axios"; +import request from "../Utils/request/request"; interface Props { children: React.ReactNode; @@ -39,19 +39,21 @@ export default function AuthUserProvider({ children, unauthorized }: Props) { ); } -const updateRefreshToken = () => { +const updateRefreshToken = async () => { const refresh = localStorage.getItem(LocalStorageKeys.refreshToken); if (!refresh) { return; } - axios - .post("/api/v1/auth/token/refresh/", { - refresh, - }) - .then((res) => { - localStorage.setItem(LocalStorageKeys.accessToken, res.data.access); - localStorage.setItem(LocalStorageKeys.refreshToken, res.data.refresh); - }); + const { res, data } = await request(routes.token_refresh, { + body: { refresh }, + }); + + if (res.status !== 200) { + return; + } + + localStorage.setItem(LocalStorageKeys.accessToken, data.access); + localStorage.setItem(LocalStorageKeys.refreshToken, data.refresh); }; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 7812fb2e175..141c35c2a59 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -11,6 +11,11 @@ function Res(): T { return {} as T; } +interface JwtTokenObtainPair { + access: string; + refresh: string; +} + const routes = { config: { path: import.meta.env.REACT_APP_CONFIG ?? "/config.json", @@ -29,6 +34,7 @@ const routes = { token_refresh: { path: "/api/v1/auth/token/refresh", method: "POST", + TRes: Res(), }, token_verify: {