diff --git a/src/actions/index.js b/src/actions/index.js index 1fe93f5..e4a63c0 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -27,5 +27,5 @@ export const userLogin = (username, password) => async (dispatch) => { }).catch(function (error) { console.log(error); }); - console.log(response) + dispatch({ type: 'USER_LOGIN', payload: response }) }; diff --git a/src/reducers/authReducer.js b/src/reducers/authReducer.js new file mode 100644 index 0000000..9962663 --- /dev/null +++ b/src/reducers/authReducer.js @@ -0,0 +1,14 @@ +const initialState = { + user_logged_in: false, + username: '', + jwt: '' +}; + +export default (state = initialState, action) => { + switch (action.type) { + case 'USER_LOGIN': + return {jwt: action.payload} + default: + return state; + } +}; diff --git a/src/reducers/index.js b/src/reducers/index.js index fcc93a0..9274340 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,8 +1,10 @@ import { combineReducers } from 'redux'; import postsReducer from './postsReducer'; import userReducer from './userReducer'; +import authReducer from './authReducer'; export default combineReducers({ posts: postsReducer, - user: userReducer + user: userReducer, + auth: authReducer });