Fix up redux connection for auth
This commit is contained in:
parent
5a057337cd
commit
bc6dadb350
2 changed files with 5 additions and 5 deletions
|
@ -7,7 +7,7 @@ class NavBar extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
logged_in: false,
|
user_authed: false,
|
||||||
auth_menu_visible: false,
|
auth_menu_visible: false,
|
||||||
user_or_login: 'Login'
|
user_or_login: 'Login'
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ class NavBar extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { user } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="ui four item secondary menu">
|
<div className="ui four item secondary menu">
|
||||||
|
@ -28,7 +29,7 @@ class NavBar extends Component {
|
||||||
<NavLink to="/posts/" className='item' activeClassName='active'>Posts</NavLink>
|
<NavLink to="/posts/" className='item' activeClassName='active'>Posts</NavLink>
|
||||||
<NavLink to="/about/" className='item' activeClassName='active'>About</NavLink>
|
<NavLink to="/about/" className='item' activeClassName='active'>About</NavLink>
|
||||||
<div onClick={this.handleLoginDropdown} className='item ui button dropdown'>
|
<div onClick={this.handleLoginDropdown} className='item ui button dropdown'>
|
||||||
{this.state.user_or_login}
|
{user.user_authed ? user.username : 'Login'}
|
||||||
<i className="dropdown icon"></i>
|
<i className="dropdown icon"></i>
|
||||||
<AuthMenu auth_menu_visible={this.state.auth_menu_visible} close={ () => this.setState({auth_menu_visible: false})}></AuthMenu>
|
<AuthMenu auth_menu_visible={this.state.auth_menu_visible} close={ () => this.setState({auth_menu_visible: false})}></AuthMenu>
|
||||||
</div>
|
</div>
|
||||||
|
@ -40,8 +41,7 @@ class NavBar extends Component {
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
return {
|
return {
|
||||||
user_authed: state.user_authed,
|
user: state.auth,
|
||||||
username: state.username
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default (state = initialState, action) => {
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
var data = JSON.parse(atob(action.payload.data.split('.')[1]))
|
var data = JSON.parse(atob(action.payload.data.split('.')[1]))
|
||||||
return {...state, ...{
|
return {...state, ...{
|
||||||
user_logged_in: true,
|
user_authed: true,
|
||||||
username: data.username,
|
username: data.username,
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue