{"size": 693, "ext": "js", "max_stars_repo_path": "client/actions/user.js", "max_stars_repo_name": "JeromeDane/comic-tracker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/actions/user.js", "max_issues_repo_name": "JeromeDane/comic-tracker", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/actions/user.js", "max_forks_repo_name": "JeromeDane/comic-tracker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.75, "max_line_length": 51, "alphanum_fraction": 0.6118326118}
import {fromJS} from 'immutable'

export const USER_UPDATE = 'USER_UPDATE'

export const setUser = user => {
  return {type: USER_UPDATE, user: fromJS(user)}
}

export const clearUser = () =>
  dispatch => {
    fetch('/api/session', {
      method: 'post',
      credentials: 'include',
      headers: {'Content-Type': 'application/json'}
    }).then(function(response) {
      return response.json()
    }).then(user => dispatch(setUser(user)))
  }

export const fetchUser = () =>
  dispatch => {
    fetch('/api/session', {
      credentials: 'include',
      headers: {'Accept': 'application/json'}
    }).then(response => response.json())
      .then(user => dispatch(setUser(user)))
  }
