認証を処理するユニバーサル アプリでは、各ユーザーが独自の Cookie を持つことを考慮する必要があります。そのため、彼の初期のリクエスト オブジェクトを保存して、彼の将来の API 呼び出しを彼の Cookie で装飾できるようにする必要があります。redux-saga でそれを処理する方法がわかりません。ユーザー要求オブジェクトをラップするオブジェクトを各サガに挿入するカスタム ミドルウェアで作業を行う必要があると思います。少なくとも、それでうまくいくと思いますが、それを完全に達成する方法がわかりません。
私はそのようなことについて考えていました:
export function* loadUser(action, api) { // Inject the object that wrap the initial user request object here
try {
const user = yield call(api.loadUser, action.payload); // So the request would be decorated behind this call
yield put(actions.loadUserSuccess(user));
} catch(e) {
yield put(actions.loadUserFail(e));
}
}
export default function* rootUserSagas() {
yield* takeLatest(LOAD_USER_REQUEST, loadUser);
}
店を作る上でやるべきことがあるんだろうな
export function configureStore(initialState = {}, req) {
const api = new Api(req);
// Then what to do with the api object to get it back into sagas?
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
rootReducer,
initialState,
applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(rootSaga);
return store;
};