Bugfix: Refresh Token Renovation (#1511)
bugfix: fix the refresh token renovation
This commit is contained in:
parent
c0cbb0776e
commit
0a3401640d
3 changed files with 13 additions and 14 deletions
|
|
@ -98,7 +98,7 @@ async def refresh_token(request: Request, response: Response, settings_service=D
|
||||||
response.set_cookie(
|
response.set_cookie(
|
||||||
"refresh_token_lf",
|
"refresh_token_lf",
|
||||||
tokens["refresh_token"],
|
tokens["refresh_token"],
|
||||||
httponly=auth_settings.REFRESH_TOKEN_HTTPONLY,
|
httponly=auth_settings.REFRESH_HTTPONLY,
|
||||||
samesite=auth_settings.REFRESH_SAME_SITE,
|
samesite=auth_settings.REFRESH_SAME_SITE,
|
||||||
secure=auth_settings.REFRESH_SECURE,
|
secure=auth_settings.REFRESH_SECURE,
|
||||||
expires=auth_settings.REFRESH_TOKEN_EXPIRE_MINUTES * 60,
|
expires=auth_settings.REFRESH_TOKEN_EXPIRE_MINUTES * 60,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import axios, { AxiosError, AxiosInstance } from "axios";
|
import axios, { AxiosError, AxiosInstance } from "axios";
|
||||||
import { useContext, useEffect } from "react";
|
import { useContext, useEffect } from "react";
|
||||||
import { Cookies } from "react-cookie";
|
import { Cookies } from "react-cookie";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { renewAccessToken } from ".";
|
import { renewAccessToken } from ".";
|
||||||
import { BuildStatus } from "../../constants/enums";
|
import { BuildStatus } from "../../constants/enums";
|
||||||
import { AuthContext } from "../../contexts/authContext";
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
|
|
@ -17,26 +16,25 @@ function ApiInterceptor() {
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
let { accessToken, login, logout, authenticationErrorCount, autoLogin } =
|
let { accessToken, login, logout, authenticationErrorCount, autoLogin } =
|
||||||
useContext(AuthContext);
|
useContext(AuthContext);
|
||||||
const navigate = useNavigate();
|
|
||||||
const cookies = new Cookies();
|
const cookies = new Cookies();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const interceptor = api.interceptors.response.use(
|
const interceptor = api.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
async (error: AxiosError) => {
|
async (error: AxiosError) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 403 || error.response?.status === 401) {
|
||||||
const accessToken = cookies.get("access_token_lf");
|
if (!autoLogin) {
|
||||||
|
|
||||||
if (accessToken && !autoLogin) {
|
|
||||||
checkErrorCount();
|
checkErrorCount();
|
||||||
await tryToRenewAccessToken(error);
|
const acceptedRequest = await tryToRenewAccessToken(error);
|
||||||
}
|
|
||||||
|
|
||||||
if (!accessToken && error?.config?.url?.includes("login")) {
|
const accessToken = cookies.get("access_token_lf");
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return logout();
|
if (!accessToken && error?.config?.url?.includes("login")) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return acceptedRequest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await clearBuildVerticesState(error);
|
await clearBuildVerticesState(error);
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|
@ -116,6 +114,7 @@ function ApiInterceptor() {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearBuildVerticesState(error);
|
||||||
logout();
|
logout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ export default function StorePage(): JSX.Element {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.response.status === 403 || err.response.status === 401) {
|
if (err.response?.status === 403 || err.response?.status === 401) {
|
||||||
setValidApiKey(false);
|
setValidApiKey(false);
|
||||||
} else {
|
} else {
|
||||||
setSearchData([]);
|
setSearchData([]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue