autenticacion.js
899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}
}