Last active
June 10, 2017 14:27
-
-
Save stepankuzmin/e0935288fe5715d8a742e3f95e86960b to your computer and use it in GitHub Desktop.
authentication with react-router-redux 5.x and redux-saga https://medium.com/@stepankuzmin/authentication-with-react-router-redux-5-x-and-redux-saga-55da66b54be7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { combineReducers } from 'redux' | |
| import { routerReducer } from 'react-router-redux'; | |
| export const AUTH_REQUEST = 'AUTH_REQUEST'; | |
| export const AUTH_SUCCESS = 'AUTH_SUCCESS'; | |
| export const AUTH_FAILURE = 'AUTH_FAILURE'; | |
| export const authorize = (login, password) => ({ | |
| type: AUTH_REQUEST, | |
| payload: { login, password } | |
| }); | |
| const initialState = { | |
| token: localStorage.getItem('token'), | |
| error: null | |
| }; | |
| const authReducer = (state = initialState, { type, payload }) => { | |
| switch (type) { | |
| case AUTH_SUCCESS: { | |
| return { ...state, token: payload }; | |
| } | |
| case AUTH_FAILURE: { | |
| return { ...state, error: payload } | |
| } | |
| default: | |
| return state; | |
| } | |
| }; | |
| const reducer = combineReducers({ | |
| auth: authReducer, | |
| router: routerReducer | |
| }); | |
| export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment