mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { configureStore } from '@reduxjs/toolkit';
|
|
import { baseApi } from '@ema-platform/api';
|
|
import { authReducer, signupReducer, configureAuthStorage, authStorage } from '@ema-platform/auth';
|
|
import { licensesReducer } from '../features/licenses/store/licenses.slice';
|
|
import type { AuthUser } from '@ema-platform/auth';
|
|
|
|
configureAuthStorage('ema-portal');
|
|
|
|
const preloadedAuth = (() => {
|
|
const token = authStorage.getToken();
|
|
const user = authStorage.getUser<AuthUser>();
|
|
if (token && user) {
|
|
return { token, user, isAuthenticated: true };
|
|
}
|
|
return undefined;
|
|
})();
|
|
|
|
export const store = configureStore({
|
|
reducer: {
|
|
auth: authReducer,
|
|
signup: signupReducer,
|
|
licenses: licensesReducer,
|
|
[baseApi.reducerPath]: baseApi.reducer,
|
|
},
|
|
preloadedState: preloadedAuth ? { auth: preloadedAuth } : undefined,
|
|
middleware: (getDefaultMiddleware) =>
|
|
getDefaultMiddleware().concat(baseApi.middleware),
|
|
});
|
|
|
|
export type RootState = ReturnType<typeof store.getState>;
|
|
export type AppDispatch = typeof store.dispatch;
|