Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created December 30, 2015 14:31
Show Gist options
  • Save karlbright/4e5a6e49f46ca8006289 to your computer and use it in GitHub Desktop.
Save karlbright/4e5a6e49f46ca8006289 to your computer and use it in GitHub Desktop.
import Immutable from 'immutable'
import { LOGIN, LOGIN_SUCCESS, LOGIN_FAILURE } from 'actions/authentication'
const initialState = Immutable.Map({ loggedIn: false, loggingIn: false })
export default function authenticationReducer (state = initialState, action) {
const pending = state.merge({ loggedIn: false, loggingIn: true })
const success = state.merge({ loggedIn: true, loggingIn: false, token: action.payload.token })
const failure = state.merge({ loggedIn: false, loggingIn: false, error: action.error })
switch (action.type) {
case AUTHENTICATE: return pending
case AUTHENTICATE_SUCCESS: return success
case AUTHENTICATION_FAILURE: return failure
case VERIFY_TOKEN: return pending
case VERIFY_TOKEN_SUCCESS: return success
case VERIFY_TOKEN_FAILURE: return failure
default: return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment