fix(auth): fix circular import problem by changing the way the authHttpClient gets accessToken; replace individual calls mocks with the common ones

This commit is contained in:
Ilia Mashkov
2026-03-18 09:10:17 +03:00
parent b75e805f54
commit 2afbd73a31
24 changed files with 135 additions and 85 deletions

View File

@@ -3,8 +3,9 @@ import type { AuthStore, AuthStoreState } from "../../types/store";
import { login, logout, refresh, register } from "../../../api";
import { callApi } from "shared/utils";
import { UNEXPECTED_ERROR_MESSAGE } from "shared/config";
import { authHttpClient } from "../../../api/config/authApi/authApi";
const defaultStoreState: Readonly<AuthStoreState> = {
export const defaultStoreState: Readonly<AuthStoreState> = {
user: undefined,
status: "idle",
accessToken: undefined,
@@ -13,7 +14,7 @@ const defaultStoreState: Readonly<AuthStoreState> = {
export const useAuthStore = create<AuthStore>()((set) => ({
...defaultStoreState,
reset: () => set({ ...defaultStoreState }),
login: async (loginData) => {
set({ status: "loading" });
try {
@@ -108,3 +109,5 @@ export const useAuthStore = create<AuthStore>()((set) => ({
}
},
}));
authHttpClient.setTokenGetter(() => useAuthStore.getState().accessToken);