1
0
Fork 0

Pass down username to state

This commit is contained in:
Amarpreet Minhas 2019-09-16 21:30:18 -04:00
parent 45243c7e26
commit 92ef06cafc
4 changed files with 9 additions and 3 deletions

View file

@ -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 })
}
};

View file

@ -67,7 +67,7 @@ class AuthMenu extends Component {
this.setState(state => ({
auth_menu_visible: false
}))
console.log(res)
this.props.close()
}
)
.catch(err => {

View file

@ -29,7 +29,7 @@ class NavBar extends Component {
<div onClick={this.handleLoginDropdown} className='item ui button dropdown'>
Login
<i className="dropdown icon"></i>
<AuthMenu auth_menu_visible={this.state.auth_menu_visible}></AuthMenu>
<AuthMenu auth_menu_visible={this.state.auth_menu_visible} close={ () => this.setState({auth_menu_visible: false})}></AuthMenu>
</div>
</div>
</div>

View file

@ -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: