summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/auth/auth.reducer.js
blob: 05741f3af487fb595c48b59949f9beee256a5df2 (plain)
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
import * as types from 'app/types'
import { getDefault } from 'app/session'

const initialState = {
  logged_in: !!getDefault('access_token', false),
  user_id: null,
  user: null,
}

export default function authReducer(state = initialState, action) {
  // console.log(action.type, action)
  switch (action.type) {
    case types.auth.logged_in:
      return {
        ...state,
        logged_in: true,
        user_id: action.user_id,
        user: null,
      }
    case types.auth.logged_out:
      return {
        ...state,
        logged_in: false,
        user_id: null,
        user: null,
      }
    case types.user.show:
      if (action.data.res.id !== state.user_id) {
        return state
      }
      return {
        ...state,
        user: {
          ...action.data.res,
        }
      }
    default:
      return state
  }
}