UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

43 lines 1.54 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.baseApi = void 0; var react_1 = require("@reduxjs/toolkit/query/react"); var env_1 = require("../../utils/env"); // Base query that uses the current project context and auth var createBaseQuery = function () { return (0, react_1.fetchBaseQuery)({ baseUrl: (0, env_1.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 exports.baseApi = (0, react_1.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) exports._b = _a = exports.baseApi; //# sourceMappingURL=baseApi.js.map