2026-03-17 14:08:29 +03:00
|
|
|
import { useAuthStore } from "../../../model";
|
2026-03-17 09:59:37 +03:00
|
|
|
import { api as baseApi } from "shared/config";
|
|
|
|
|
|
|
|
|
|
// Extend base API with authentication hooks
|
|
|
|
|
export const api = baseApi.extend({
|
|
|
|
|
hooks: {
|
|
|
|
|
beforeRequest: [
|
|
|
|
|
(request) => {
|
2026-03-17 14:08:29 +03:00
|
|
|
const token = useAuthStore.getState().accessToken;
|
|
|
|
|
|
|
|
|
|
if (token) {
|
|
|
|
|
request.headers.set("Authorization", `Bearer ${token}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 09:59:37 +03:00
|
|
|
return request;
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
afterResponse: [
|
|
|
|
|
async (request, options, response) => {
|
|
|
|
|
// Refresh token logic
|
|
|
|
|
return response;
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|