|
|
@ -1,15 +1,28 @@ |
|
|
|
|
|
|
|
// store/index.ts
|
|
|
|
import { configureStore } from '@reduxjs/toolkit'; |
|
|
|
import { configureStore, combineReducers } from '@reduxjs/toolkit'; |
|
|
|
import { persistStore, persistReducer } from 'redux-persist'; |
|
|
|
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web
|
|
|
|
import authReducer from './authSlice'; |
|
|
|
|
|
|
|
const rootReducer = combineReducers({ |
|
|
|
auth: authReducer, |
|
|
|
}); |
|
|
|
|
|
|
|
const persistConfig = { |
|
|
|
key: 'root', |
|
|
|
storage, |
|
|
|
whitelist: ['auth'], // only auth will be persisted
|
|
|
|
}; |
|
|
|
|
|
|
|
const persistedReducer = persistReducer(persistConfig, rootReducer); |
|
|
|
|
|
|
|
const store = configureStore({ |
|
|
|
reducer: { |
|
|
|
auth: authReducer, |
|
|
|
}, |
|
|
|
reducer: persistedReducer, |
|
|
|
}); |
|
|
|
|
|
|
|
export type RootState = ReturnType<typeof store.getState>; |
|
|
|
const persistor = persistStore(store); |
|
|
|
|
|
|
|
export type RootState = ReturnType<typeof rootReducer>; |
|
|
|
export type AppDispatch = typeof store.dispatch; |
|
|
|
|
|
|
|
export default store; |
|
|
|
export { store, persistor }; |