client/src/reducers/authReducer.js
changeset 129 d48946d164c6
parent 101 e165aa89ac82
child 130 78246db1cbac
equal deleted inserted replaced
128:34a75bd8d0b9 129:d48946d164c6
     1 import Immutable from 'immutable';
     1 import Immutable from 'immutable';
     2 import * as types from '../constants/actionTypes';
     2 import * as types from '../constants/actionTypes';
     3 import UserRecord from '../store/userRecord';
     3 import UserRecord from '../store/userRecord';
     4 import asyncRequest from '../constants/asyncRequest';
     4 import asyncRequest from '../constants/asyncRequest';
       
     5 import uuidV4 from 'uuid/v4';
     5 
     6 
     6 export const isAuthenticated = (state = false, action) => {
     7 export const isAuthenticated = (state = false, action) => {
     7   switch (action.type) {
     8   switch (action.type) {
     8     case types.AUTH_DEAUTHENTICATE:
     9     case types.AUTH_DEAUTHENTICATE:
     9     case types.AUTH_LOGOUT:
    10     case types.AUTH_LOGOUT:
    40     case types.AUTH_STORE_TOKEN:
    41     case types.AUTH_STORE_TOKEN:
    41       return action.token;
    42       return action.token;
    42     default:
    43     default:
    43       return state;
    44       return state;
    44   }
    45   }
       
    46 }
       
    47 
       
    48 export const clientId = (state = null, action) => {
       
    49   switch (action.type) {
       
    50     case types.AUTH_DEAUTHENTICATE:
       
    51     case types.AUTH_LOGOUT:
       
    52       return null;
       
    53     case types.AUTH_LOGIN_SUCCESS:
       
    54       return uuidV4();
       
    55     default:
       
    56       return state;
       
    57   }
       
    58 
    45 }
    59 }
    46 
    60 
    47 export const login = (state = asyncRequest, action) => {
    61 export const login = (state = asyncRequest, action) => {
    48   switch (action.type) {
    62   switch (action.type) {
    49     case types.AUTH_LOGIN_REQUEST:
    63     case types.AUTH_LOGIN_REQUEST: