feat: lots of updates

This commit is contained in:
zerosoul
2022-01-27 22:06:44 +08:00
commit e18c7323a6
72 changed files with 12432 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import { fetchBaseQuery } from "@reduxjs/toolkit/query";
import BASE_URL, { tokenHeader } from "../config";
// const whiteList = [
// "/resource/avatar",
// "/resource/company/logo",
// "/resource/thumbnail",
// "/resource/image",
// "/token/login",
// "/token/renew",
// "/user",
// "/admin/system/company",
// ];
const baseQuery = fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState }) => {
const { token } = getState().authData;
if (token) {
headers.set(tokenHeader, token);
}
return headers;
},
});
const baseQueryWithReauth = async (args, api, extraOptions) => {
let result = await baseQuery(args, api, extraOptions);
if (result.error && result.error.status === 401) {
// try to get a new token with refreshToken
// const refreshResult = await baseQuery('/refreshToken', api, extraOptions);
// if (refreshResult.data) {
// // store the new token
// api.dispatch(tokenReceived(refreshResult.data));
// // retry the initial query
// result = await baseQuery(args, api, extraOptions);
// } else {
// api.dispatch(loggedOut());
// }
}
return result;
};
export default baseQueryWithReauth;