Redux: What is the correct place to save cookie after login request?
<p>I have the following situation: The user enters his credentials and clicks a <em>Login</em> button. An API call is done in the action creator via <code>redux-thunk</code>. When the API call was successful, another action is dispatched containing the response from the server. After the (successful) login I want to store the users session id in a cookie (via <code>react-cookie</code>).</p>

<p><strong>Action creator</strong></p>

<pre><code>export function initiateLoginRequest(username, password) {
  return function(dispatch) {
    dispatch(loginRequestStarting())

    return fetch('http://path.to/api/v1/login',
      {
        method: 'POST',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          username: username,
          password: password
        })
      })
      .then(checkStatus)
      .then(parseJSON)
      .then(function(data) {
        dispatch(loginRequestSuccess(data))
      })
      .catch(function(error) {
        dispatch(loginRequestError(error))
      })
  }
}

export function loginRequestSuccess(user) {
  return {
    type: ActionTypes.LOGIN_REQUEST_SUCCESS,
    user
  }
}
</code></pre>

<p><strong>Reducer</strong></p>

<pre><code>export default function user(state = initialState, action) {
  switch (action.type) {
    case ActionTypes.LOGIN_REQUEST_SUCCESS:
      cookie.save('sessionId', action.user.sid, { path: '/' })
      return merge({}, state, {
        sessionId: action.user.sid,
        id: action.user.id,
        firstName: action.user.first_name,
        lastName: action.user.last_name,
        isAuthenticated: true
      })
    default:
      return state
  }
}
</code></pre>

<p>Right now the reducer responsible for <em>LOGIN_REQUEST_SUCCESS</em> saves the cookie. I know the reducer has to be <strong>a pure function</strong>.</p>

<p>Is saving a cookie in the reducer violating this principle? Would it be better to save the cookie inside the action creator?</p>