function* loginUser(action) {
  try {
    // clear any existing error on the login page
    yield put({ type: 'CLEAR_LOGIN_ERROR' });

    const config = {
      headers: { 'Content-Type': 'application/json' },
      withCredentials: true,
    };

    // send the action.payload as the body
    // the config includes credentials which
    // allow the server session to recognize the user
    yield axios.post('/api/user/login', action.payload, config);

    // after the user has logged in
    // get the user information from the server
    yield put({ type: 'FETCH_USER' });
  } catch (error) {
    console.log('Error with user login:', error);
    if (error.response.status === 401) {
      // The 401 is the error status sent from passport
      // if user isn't in the database or
      // if the username and password don't match in the database
      yield put({ type: 'LOGIN_FAILED' });
    }
  }
}
// worker Saga: will be fired on "LOGIN" actions
worker Saga: will be fired on "LOGIN" actions
worker Saga : will be fired on " LOGIN " actions
function* loginUser(action) {
  try {
    yield put({ type: 'CLEAR_LOGIN_ERROR' });
    const config = {
      headers: { 'Content-Type': 'application/json' },
      withCredentials: true,
    };
    yield axios.post('/api/user/login', action.payload, config);
    yield put({ type: 'FETCH_USER' });
  } catch (error) {
    console.log('Error with user login:', error);
    if (error.response.status === 401) {
      yield put({ type: 'LOGIN_FAILED' });
    }
  }
}
function * loginUser ( action ) { try { yield put ( { type : 'CLEAR_LOGIN_ERROR' } ) ; const config = { headers : { 'Content-Type' : 'application/json' } , withCredentials : true , } ; yield axios . post ( '/api/user/login' , action . payload , config ) ; yield put ( { type : 'FETCH_USER' } ) ; } catch ( error ) { console . log ( 'Error with user login:' , error ) ; if ( error . response . status === 401 ) { yield put ( { type : 'LOGIN_FAILED' } ) ; } } }
worker Saga: will be fired on "LOGIN" actions
worker Saga : will be fired on " LOGIN " actions
// clear any existing error on the login page // send the action.payload as the body // the config includes credentials which // allow the server session to recognize the user // after the user has logged in // get the user information from the server // The 401 is the error status sent from passport // if user isn't in the database or // if the username and password don't match in the database