@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
40 lines • 1.43 kB
JavaScript
var _a;
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { getApiBaseUrl } from "../../utils/env";
// Base query that uses the current project context and auth
var createBaseQuery = function () {
return fetchBaseQuery({
baseUrl: getApiBaseUrl(),
credentials: 'include', // Equivalent to withCredentials: true
prepareHeaders: function (headers, _a) {
var getState = _a.getState;
// Add Content-Type header
headers.set('Content-Type', 'application/json');
// Get access token from Redux state
var state = getState();
var accessToken = state.auth.accessToken;
// Add Authorization header if we have a token
if (accessToken) {
headers.set('Authorization', "Bearer ".concat(accessToken));
}
return headers;
},
});
};
// Create the base API slice
export var baseApi = createApi({
reducerPath: 'api',
baseQuery: createBaseQuery(),
tagTypes: [
'AppNotification',
'List',
'User',
'Entity',
// Future tag types:
// 'Comment',
],
endpoints: function () { return ({}); }, // Endpoints will be injected by feature APIs
});
// Export hooks for use in components (will be populated by injected endpoints)
export var _b = _a = baseApi;
//# sourceMappingURL=baseApi.js.map