Ф
// Prepare redux store
export const configureStore: MakeStore = (
initialState: Partial<RootState>,
options,
) => {
// Populate store on server. Pretty awful code
if (options.isServer && options.req && options.req.headers.cookie) {
// @ts-ignore
const authData: AuthData = jwt.decode(
(options.req as IncomingMessage & {
cookies: { access_token: string };
}).cookies.access_token,
);
initialState = initialState || {
auth: {
authData: authData || {},
authorized: !!authData,
},
};
}
// Create store with root state
const store = createStore<RootState, Action, {}, {}>(
rootReducer,
initialState,
composeWithDevTools(),
);
return store;
};
и в _app.tsx:
export default withRedux(configureStore)(MyApp);