From 92ef06cafcb31c01201352723506ef7d7b2d5cd8 Mon Sep 17 00:00:00 2001 From: Asara Date: Mon, 16 Sep 2019 21:30:18 -0400 Subject: [PATCH] Pass down username to state --- src/actions/index.js | 7 ++++++- src/components/AuthMenu.js | 2 +- src/components/NavBar.js | 2 +- src/reducers/authReducer.js | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/actions/index.js b/src/actions/index.js index d894f68..0959fec 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -23,5 +23,10 @@ export const userLogin = (username, password) => async (dispatch) => { username: username, password: password }) - dispatch({ type: 'USER_LOGIN', payload: response }) + if (response.status === 401) { + alert("Please check your credentials") + } + if (response.status === 200) { + dispatch({ type: 'USER_LOGIN', payload: response }) + } }; diff --git a/src/components/AuthMenu.js b/src/components/AuthMenu.js index 95f2b73..9ef009c 100644 --- a/src/components/AuthMenu.js +++ b/src/components/AuthMenu.js @@ -67,7 +67,7 @@ class AuthMenu extends Component { this.setState(state => ({ auth_menu_visible: false })) - console.log(res) + this.props.close() } ) .catch(err => { diff --git a/src/components/NavBar.js b/src/components/NavBar.js index ecc3f8e..cc0e320 100644 --- a/src/components/NavBar.js +++ b/src/components/NavBar.js @@ -29,7 +29,7 @@ class NavBar extends Component {
Login - + this.setState({auth_menu_visible: false})}>
diff --git a/src/reducers/authReducer.js b/src/reducers/authReducer.js index 164f00d..c24d51b 100644 --- a/src/reducers/authReducer.js +++ b/src/reducers/authReducer.js @@ -9,6 +9,7 @@ export default (state = initialState, action) => { case 'USER_LOGIN': return {...state, ...{ jwt: action.payload.data.jwt, + username: action.payload.data.username, user_logged_in: true }} default: