import type { PayloadAction } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit"; import type { IAuthStore, SetAuthActionPayload } from "./auth-store.types"; export const initialState: IAuthStore = { tokenInfo: null, user: null, status: "idle", }; const authSlice = createSlice({ name: "auth", initialState, reducers: { setAuthData(state, action: PayloadAction) { state.tokenInfo = action.payload.tokenInfo; state.user = action.payload.user ?? null; if (state.status !== "done") { state.status = "done"; } }, clear(state) { state.user = null; state.tokenInfo = null; }, setStatus(state, action: PayloadAction) { state.status = action.payload; }, }, }); export const authReducer = authSlice.reducer; export const authActions = authSlice.actions;