autenticacion.js 899 Bytes
import { merge } from 'ramda'
import {
  ACCESS_TOKEN_REQUESTED,
  ACCESS_TOKEN_RECEIVED,
  ACCESS_TOKEN_FAILED
} from '../actions/autenticacion'

const initial = {
  authenticated: false,
  loading: false,
  token: '',
  tokenTime: null,
  error: null
}

export default (state = initial, action) => {
  switch (action.type) {
    case ACCESS_TOKEN_REQUESTED:
      return merge(state, {
          loading: true,
          error: null
      })
    case ACCESS_TOKEN_RECEIVED:
      return merge(state, {
        authenticated: true,
        loading: false,
        token: action.token.accessToken,
        tokenTime: action.token.receivedAt,
        error: null
      })
    case ACCESS_TOKEN_FAILED:
      return merge(state, {
        authenticated: false,
        loading: false,
        token: '',
        tokenTime: 0,
        error: action.error
      })
    default:
      return state
  }
}