mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 06:29:02 +08:00
feat: refresh token is fixed (#1049)
This commit is contained in:
parent
05c923df9b
commit
5f529e1c10
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable sonarjs/cognitive-complexity */
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import getLocalStorageApi from 'api/browser/localstorage/get';
|
import getLocalStorageApi from 'api/browser/localstorage/get';
|
||||||
@ -31,32 +32,54 @@ const interceptorsRequestResponse = (
|
|||||||
const interceptorRejected = async (
|
const interceptorRejected = async (
|
||||||
value: AxiosResponse<any>,
|
value: AxiosResponse<any>,
|
||||||
): Promise<AxiosResponse<any>> => {
|
): Promise<AxiosResponse<any>> => {
|
||||||
if (axios.isAxiosError(value) && value.response) {
|
try {
|
||||||
const { response } = value;
|
if (axios.isAxiosError(value) && value.response) {
|
||||||
console.log(response);
|
const { response } = value;
|
||||||
// reject the refresh token error
|
console.log(response);
|
||||||
if (response.status === 401 && response.config.url !== '/login') {
|
// reject the refresh token error
|
||||||
const response = await loginApi({
|
if (response.status === 401 && response.config.url !== '/login') {
|
||||||
refreshToken: store.getState().app.user?.accessJwt,
|
const response = await loginApi({
|
||||||
});
|
refreshToken: store.getState().app.user?.refreshJwt,
|
||||||
|
});
|
||||||
|
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
await afterLogin(
|
await afterLogin(
|
||||||
response.payload.userId,
|
response.payload.userId,
|
||||||
response.payload.accessJwt,
|
response.payload.accessJwt,
|
||||||
response.payload.refreshJwt,
|
response.payload.refreshJwt,
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
|
const reResponse = await axios(
|
||||||
|
`${value.config.baseURL}${value.config.url?.substring(1)}`,
|
||||||
|
{
|
||||||
|
method: value.config.method,
|
||||||
|
headers: {
|
||||||
|
...value.config.headers,
|
||||||
|
Authorization: `Bearer ${response.payload.accessJwt}`,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
...JSON.parse(value.config.data || '{}'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (reResponse.status === 200) {
|
||||||
|
return await Promise.resolve(reResponse);
|
||||||
|
}
|
||||||
|
return await Promise.reject(reResponse);
|
||||||
|
}
|
||||||
|
Logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
// when refresh token is expired
|
||||||
|
if (response.status === 401 && response.config.url === '/login') {
|
||||||
Logout();
|
Logout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return await Promise.reject(value);
|
||||||
// when refresh token is expired
|
} catch (error) {
|
||||||
if (response.status === 401 && response.config.url === '/login') {
|
return Promise.reject(value);
|
||||||
Logout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Promise.reject(value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Typography } from 'antd';
|
import { Typography } from 'antd';
|
||||||
import getUserVersion from 'api/user/getVersion';
|
import getUserVersion from 'api/user/getVersion';
|
||||||
import Spinner from 'components/Spinner';
|
import Spinner from 'components/Spinner';
|
||||||
import ROUTES from 'constants/routes';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useQueries } from 'react-query';
|
import { useQueries } from 'react-query';
|
||||||
@ -15,8 +14,6 @@ function SignUp(): JSX.Element {
|
|||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { isLoggedIn } = useSelector<AppState, AppReducer>((state) => state.app);
|
const { isLoggedIn } = useSelector<AppState, AppReducer>((state) => state.app);
|
||||||
|
|
||||||
useLoggedInNavigate(ROUTES.APPLICATION);
|
|
||||||
|
|
||||||
const [versionResponse] = useQueries([
|
const [versionResponse] = useQueries([
|
||||||
{
|
{
|
||||||
queryFn: getUserVersion,
|
queryFn: getUserVersion,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user