feat: lots updates
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
import BASE_URL from "../config";
|
||||
|
||||
import { createApi } from "@reduxjs/toolkit/query/react";
|
||||
import baseQuery from "./base.query";
|
||||
export const authApi = createApi({
|
||||
reducerPath: "auth",
|
||||
baseQuery: fetchBaseQuery({ baseUrl: BASE_URL }),
|
||||
baseQuery,
|
||||
endpoints: (builder) => ({
|
||||
login: builder.mutation({
|
||||
query: (credentials) => ({
|
||||
@@ -19,7 +18,10 @@ export const authApi = createApi({
|
||||
// return resp;
|
||||
// },
|
||||
}),
|
||||
logout: builder.query({
|
||||
query: () => ({ url: `token/logout` }),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const { useLoginMutation } = authApi;
|
||||
export const { useLoginMutation, useLazyLogoutQuery } = authApi;
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
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 whiteList = ["login"];
|
||||
const baseQuery = fetchBaseQuery({
|
||||
baseUrl: BASE_URL,
|
||||
prepareHeaders: (headers, { getState }) => {
|
||||
prepareHeaders: (headers, { getState, endpoint }) => {
|
||||
console.log("req", endpoint);
|
||||
const { token } = getState().authData;
|
||||
if (token) {
|
||||
if (token && !whiteList.includes(endpoint)) {
|
||||
headers.set(tokenHeader, token);
|
||||
}
|
||||
return headers;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createApi } from "@reduxjs/toolkit/query/react";
|
||||
import baseQuery from "./base.query";
|
||||
import { REHYDRATE } from "redux-persist";
|
||||
export const channelApi = createApi({
|
||||
reducerPath: "groups",
|
||||
reducerPath: "channel",
|
||||
baseQuery,
|
||||
extractRehydrationInfo(action, { reducerPath }) {
|
||||
if (action.type === REHYDRATE) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import baseQuery from "./base.query";
|
||||
import BASE_URL from "../config";
|
||||
import { REHYDRATE } from "redux-persist";
|
||||
export const contactApi = createApi({
|
||||
reducerPath: "contacts",
|
||||
reducerPath: "contact",
|
||||
baseQuery,
|
||||
extractRehydrationInfo(action, { reducerPath }) {
|
||||
if (action.type === REHYDRATE) {
|
||||
|
||||
@@ -14,9 +14,9 @@ export const serverApi = createApi({
|
||||
// },
|
||||
endpoints: (builder) => ({
|
||||
getServer: builder.query({
|
||||
query: () => ({ url: `admin/system/company` }),
|
||||
query: () => ({ url: `admin/system/organization` }),
|
||||
transformResponse: (data) => {
|
||||
data.logo = `${BASE_URL}/resource/company/logo`;
|
||||
data.logo = `${BASE_URL}/resource/organization/logo`;
|
||||
return data;
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user