12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import { createReducer } from '../utils/reducer'
- import { REQUEST_OK, REQUEST_KO } from '../constants/ActionTypes'
- import { has, isEqual } from 'lodash'
- const initialState = {
- isAuthenticated: false
- }
- /**
- *
- * @param {*} state
- * @param {*} action
- */
- const checkAuthentication = (isAuthenticated, action) => {
- if (!has(action.payload, 'status')) {
- return isAuthenticated
- }
- if (isEqual(action.payload.status, 401)) {
- return false
- }
- return isAuthenticated
- }
- /**
- *
- */
- const authenticationCheckReducer = createReducer(initialState, {
- [REQUEST_OK]: checkAuthentication,
- [REQUEST_KO]: checkAuthentication
- })
- /**
- *
- * @param {*} state
- * @param {*} action
- */
- export const auth = (state = initialState, action) => {
- return {
- isAuthenticated: authenticationCheckReducer(state.isAuthenticated, action)
- }
- }
|