Currently I’m working with a chat application which is based on json-server now the problem is while I’m requesting for conversations with like search (http://localhost:9000/[email protected]&_sort=timestamp&_order=desc&_page=1&_limit=5) it showing 200 response but data won’t shown up! while I check the json server it showing “missing authorization header”
Here is my conversation api
import { apiSlice } from "../api/apiSlice";
export const conversationsApi = apiSlice.injectEndpoints({
endpoints: (builder) => ({
//endpoints here
getConversations: builder.query({
query: (email) => `/conversations?participants_like=${email}&_sort=timestamp&_order=desc&_page=1&_limit=5`,
})
})
})
export const {useGetConversationsQuery } = conversationsApi;
here is my converation slice
`
import { createSlice } from ‘@reduxjs/toolkit’
const initialState = {}
const conversationsSlice = createSlice({
name: “conversations”,
initialState,
reducers: {}
})
// export const { } = conversationsSlice.actions;
export default conversationsSlice.reducer;
`
here is my apiSlice
import { createApi, fetchBaseQuery } from ‘@reduxjs/toolkit/query/react’
export const apiSlice = createApi({
reducerPath: “api”,
baseQuery: fetchBaseQuery({
baseUrl: process.env.REACT_APP_API_URL,
prepareHeaders: async (headers, { getState, endpoint }) => {
const token = getState()?.auth?.accessToken;
if (token) {
headers.set(“Authorization”, Bearer ${token}
);
}
console.log(headers)
return headers;
}
}),
tagTypes: [],
endpoints: (builder) => ({
})
})