function loginCurrentUser(formData, history) {
  return dispatch => {
    const reqObj = {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(formData)
    }
    return fetch("http://localhost:3000/api/v1/auth", reqObj)
      .then(resp => resp.json())
      .then(data => {
        if (data.error) {
          alert(data.error)
        } else {
          localStorage.token = data.jwt
          dispatch(loginUser(data.user))
          dispatch(isCurrentUser(true))
          console.log(data)
          history.push(`/profile/${data.user.id}`)
        }
      })
      .catch(err => console.log(err))
  }
}
// ! Log's in user and issues token
Log's in user and issues token
Log ' s in user and issues token
function loginCurrentUser(formData, history) {
  return dispatch => {
    const reqObj = {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(formData)
    }
    return fetch("http://localhost:3000/api/v1/auth", reqObj)
      .then(resp => resp.json())
      .then(data => {
        if (data.error) {
          alert(data.error)
        } else {
          localStorage.token = data.jwt
          dispatch(loginUser(data.user))
          dispatch(isCurrentUser(true))
          console.log(data)
          history.push(`/profile/${data.user.id}`)
        }
      })
      .catch(err => console.log(err))
  }
}
function loginCurrentUser ( formData , history ) { return dispatch => { const reqObj = { method : "POST" , headers : { "Content-Type" : "application/json" } , body : JSON . stringify ( formData ) } return fetch ( "http://localhost:3000/api/v1/auth" , reqObj ) . then ( resp => resp . json ( ) ) . then ( data => { if ( data . error ) { alert ( data . error ) } else { localStorage . token = data . jwt dispatch ( loginUser ( data . user ) ) dispatch ( isCurrentUser ( true ) ) console . log ( data ) history . push ( ` ${ data . user . id } ` ) } } ) . catch ( err => console . log ( err ) ) } }
Log's in user and issues token
Log ' s in user and issues token