mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 05:54:55 +03:00
feat: create HydraApi
This commit is contained in:
parent
81f2e509c5
commit
f21a8bf784
@ -36,7 +36,9 @@ export class HydraApi {
|
|||||||
if (error.response.status === 401 && !originalRequest._retry) {
|
if (error.response.status === 401 && !originalRequest._retry) {
|
||||||
originalRequest._retry = true;
|
originalRequest._retry = true;
|
||||||
const refreshToken = this.refreshToken;
|
const refreshToken = this.refreshToken;
|
||||||
if (refreshToken) {
|
|
||||||
|
if (!refreshToken) return error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${import.meta.env.MAIN_VITE_API_URL}/auth/refresh`,
|
`${import.meta.env.MAIN_VITE_API_URL}/auth/refresh`,
|
||||||
@ -55,7 +57,7 @@ export class HydraApi {
|
|||||||
|
|
||||||
originalRequest.headers.Authorization = `Bearer ${newAccessToken}`;
|
originalRequest.headers.Authorization = `Bearer ${newAccessToken}`;
|
||||||
return axios(originalRequest); //recall Api with new token
|
return axios(originalRequest); //recall Api with new token
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
this.authToken = "";
|
this.authToken = "";
|
||||||
this.refreshToken = "";
|
this.refreshToken = "";
|
||||||
return error;
|
return error;
|
||||||
@ -64,9 +66,6 @@ export class HydraApi {
|
|||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user