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:
@@ -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);
|
||||
|
||||
@@ -21,13 +21,14 @@ export interface AuthStoreState {
|
||||
error: ApiError | Error | null;
|
||||
}
|
||||
|
||||
export type LoginAction = (data: AuthData) => void;
|
||||
export type RegisterAction = (data: AuthData) => void;
|
||||
export type LogoutAction = () => void;
|
||||
export type RefreshAction = () => void;
|
||||
export type ResetAction = () => void;
|
||||
export type LoginAction = (data: AuthData) => Promise<void>;
|
||||
export type RegisterAction = (data: AuthData) => Promise<void>;
|
||||
export type LogoutAction = () => Promise<void>;
|
||||
export type RefreshAction = () => Promise<void>;
|
||||
|
||||
export interface AuthStoreActions {
|
||||
// Async actions
|
||||
reset: ResetAction;
|
||||
login: LoginAction;
|
||||
register: RegisterAction;
|
||||
logout: LogoutAction;
|
||||
|
||||
Reference in New Issue
Block a user