Files
auth-remote-react/src/features/auth/api/config/authApi/authApi.ts

26 lines
577 B
TypeScript
Raw Normal View History

import { useAuthStore } from "../../../model";
import { api as baseApi } from "shared/config";
// Extend base API with authentication hooks
export const api = baseApi.extend({
hooks: {
beforeRequest: [
(request) => {
const token = useAuthStore.getState().accessToken;
if (token) {
request.headers.set("Authorization", `Bearer ${token}`);
}
return request;
},
],
afterResponse: [
async (request, options, response) => {
// Refresh token logic
return response;
},
],
},
});