feat(auth): add accessToken field to authStore and setup beforeRequest hook to add this token to headers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useAuthStore } from "../../../model";
|
||||
import { api as baseApi } from "shared/config";
|
||||
|
||||
// Extend base API with authentication hooks
|
||||
@@ -5,7 +6,12 @@ export const api = baseApi.extend({
|
||||
hooks: {
|
||||
beforeRequest: [
|
||||
(request) => {
|
||||
// Add authentication token to request headers
|
||||
const token = useAuthStore.getState().accessToken;
|
||||
|
||||
if (token) {
|
||||
request.headers.set("Authorization", `Bearer ${token}`);
|
||||
}
|
||||
|
||||
return request;
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user