|
|
|
@ -51,7 +51,8 @@ class Proxy { |
|
|
|
|
dispatch({ type: url, data: response.data.data, params }); |
|
|
|
|
return response.data.data; |
|
|
|
|
case 401: |
|
|
|
|
if (await this.refresh()) { |
|
|
|
|
let refresh = localStorage.getItem("refresh"); |
|
|
|
|
if (refresh && (await this.refresh(refresh))) { |
|
|
|
|
let response = await fetch(); |
|
|
|
|
dispatch({ type: url, data: response.data.data, params }); |
|
|
|
|
return response.data.data; |
|
|
|
@ -69,13 +70,16 @@ class Proxy { |
|
|
|
|
|
|
|
|
|
refresh = async () => { |
|
|
|
|
let refresh = localStorage.getItem("refresh"); |
|
|
|
|
if (!refresh) window.location.href = "/"; |
|
|
|
|
let login = await this.login( |
|
|
|
|
"user/login", |
|
|
|
|
{}, |
|
|
|
|
{ headers: { Authorization: `Bearer ${refresh}` } } |
|
|
|
|
); |
|
|
|
|
return login ? true : false; |
|
|
|
|
|
|
|
|
|
if (!refresh) return false; |
|
|
|
|
//window.location.href = "/";
|
|
|
|
|
// let login = await this.login(
|
|
|
|
|
// "user/login",
|
|
|
|
|
// {},
|
|
|
|
|
// { headers: { Authorization: `Bearer ${refresh}` } }
|
|
|
|
|
// );
|
|
|
|
|
// return login ? true : false;
|
|
|
|
|
return false; |
|
|
|
|
}; |
|
|
|
|
login = async (url, params, { dispatch }) => |
|
|
|
|
this.post(url, params, { |
|
|
|
@ -112,7 +116,7 @@ class Proxy { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return JSON.parse(userData || ''); |
|
|
|
|
return JSON.parse(userData || ""); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
const _proxy = new Proxy(); |
|
|
|
|