mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-17 06:35:54 +08:00
Merge pull request #1054 from palash-signoz/interceptor-is-updated
chore: interceptor is updated
This commit is contained in:
commit
79475bde71
@ -40,7 +40,7 @@ const afterLogin = async (
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (getUserResponse.statusCode === 200) {
|
if (getUserResponse.statusCode === 200 && getUserResponse.payload) {
|
||||||
store.dispatch<AppActions>({
|
store.dispatch<AppActions>({
|
||||||
type: LOGGED_IN,
|
type: LOGGED_IN,
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -35,7 +35,6 @@ const interceptorRejected = async (
|
|||||||
try {
|
try {
|
||||||
if (axios.isAxiosError(value) && value.response) {
|
if (axios.isAxiosError(value) && value.response) {
|
||||||
const { response } = value;
|
const { response } = value;
|
||||||
console.log(response);
|
|
||||||
// reject the refresh token error
|
// reject the refresh token error
|
||||||
if (response.status === 401 && response.config.url !== '/login') {
|
if (response.status === 401 && response.config.url !== '/login') {
|
||||||
const response = await loginApi({
|
const response = await loginApi({
|
||||||
@ -43,32 +42,37 @@ const interceptorRejected = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
await afterLogin(
|
const user = await afterLogin(
|
||||||
response.payload.userId,
|
response.payload.userId,
|
||||||
response.payload.accessJwt,
|
response.payload.accessJwt,
|
||||||
response.payload.refreshJwt,
|
response.payload.refreshJwt,
|
||||||
);
|
);
|
||||||
|
|
||||||
const reResponse = await axios(
|
if (user) {
|
||||||
`${value.config.baseURL}${value.config.url?.substring(1)}`,
|
const reResponse = await axios(
|
||||||
{
|
`${value.config.baseURL}${value.config.url?.substring(1)}`,
|
||||||
method: value.config.method,
|
{
|
||||||
headers: {
|
method: value.config.method,
|
||||||
...value.config.headers,
|
headers: {
|
||||||
Authorization: `Bearer ${response.payload.accessJwt}`,
|
...value.config.headers,
|
||||||
|
Authorization: `Bearer ${response.payload.accessJwt}`,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
...JSON.parse(value.config.data || '{}'),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data: {
|
);
|
||||||
...JSON.parse(value.config.data || '{}'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (reResponse.status === 200) {
|
if (reResponse.status === 200) {
|
||||||
return await Promise.resolve(reResponse);
|
return await Promise.resolve(reResponse);
|
||||||
|
}
|
||||||
|
Logout();
|
||||||
|
|
||||||
|
return await Promise.reject(reResponse);
|
||||||
}
|
}
|
||||||
Logout();
|
Logout();
|
||||||
|
|
||||||
return await Promise.reject(reResponse);
|
return await Promise.reject(value);
|
||||||
}
|
}
|
||||||
Logout();
|
Logout();
|
||||||
}
|
}
|
||||||
@ -80,7 +84,7 @@ const interceptorRejected = async (
|
|||||||
}
|
}
|
||||||
return await Promise.reject(value);
|
return await Promise.reject(value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(value);
|
return await Promise.reject(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const getUser = async (
|
|||||||
return {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
error: null,
|
error: null,
|
||||||
message: response.data.status,
|
message: 'Success',
|
||||||
payload: response.data,
|
payload: response.data,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user