Start working on reducer for auth
This commit is contained in:
parent
aa6f98f91f
commit
4b97b943e8
3 changed files with 18 additions and 2 deletions
|
@ -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 })
|
||||
};
|
||||
|
|
14
src/reducers/authReducer.js
Normal file
14
src/reducers/authReducer.js
Normal file
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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
|
||||
});
|
||||
|
|
Reference in a new issue