@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
47 lines • 1.75 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.replykeApiMiddleware = exports.replykeApiReducer = exports.baseApi = void 0;
const react_1 = require("@reduxjs/toolkit/query/react");
const env_1 = require("../../utils/env");
// Base query that uses the current project context and auth
const createBaseQuery = () => {
return (0, react_1.fetchBaseQuery)({
baseUrl: (0, env_1.getApiBaseUrl)(),
prepareHeaders: (headers, { getState }) => {
// Add Content-Type header
headers.set('Content-Type', 'application/json');
// Get access token from namespaced Redux state
const state = getState();
const accessToken = state.replyke?.auth?.accessToken;
// Add Authorization header if we have a token
if (accessToken) {
headers.set('Authorization', `Bearer ${accessToken}`);
}
return headers;
},
});
};
// Create the base API slice
exports.baseApi = (0, react_1.createApi)({
reducerPath: 'replykeApi',
baseQuery: createBaseQuery(),
tagTypes: [
'AppNotification',
'Collection',
'CollectionEntities',
'User',
'Entity',
'Space',
'SpaceMember',
// Future tag types:
// 'Comment',
],
endpoints: () => ({}), // Endpoints will be injected by feature APIs
});
// Export hooks for use in components (will be populated by injected endpoints)
_a = exports.baseApi;
// Exports for integration mode (users who have their own Redux store)
exports.replykeApiReducer = exports.baseApi.reducer;
exports.replykeApiMiddleware = exports.baseApi.middleware;
//# sourceMappingURL=baseApi.js.map