Last active
January 30, 2017 18:00
-
-
Save gkueny/8f754d50c1c100e0f8abb315e5cdab26 to your computer and use it in GitHub Desktop.
react admin article : https://gkueny.fr/react-admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import * as firebase from 'firebase'; | |
class HaveToLogginComponent extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
authenticate : false | |
} | |
} | |
componentDidMount() { | |
this.checkUserStatus(); | |
} | |
componentDidUpdate() { | |
this.checkUserStatus(); | |
} | |
checkUserStatus = () => { | |
firebase.auth().onAuthStateChanged( user => { | |
let statut = user | |
? true | |
: false; | |
this.updateUserStatus(statut); | |
}); | |
}; | |
updateUserStatus = (isLogIn) => { | |
// User not login, and previously authenticate | |
if (!isLogIn && this.state.authenticate) | |
this.setState({ | |
authenticate : false | |
}); | |
// User login, and previously not authenticate | |
else if (isLogIn && !this.state.authenticate) | |
this.setState({ | |
authenticate : true | |
}); | |
} | |
render() { | |
if (this.props.state.user.userLogin) | |
return this.props.children; | |
else | |
return <p> error </p>; | |
} | |
} | |
HaveToLogginComponent.propTypes = { | |
children : React.PropTypes.object | |
}; | |
export default HaveToLogginComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//react admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
export default class AdminComponent extends Component | |
{ | |
constructor() { | |
this.isAuthenticate = false; | |
} | |
componentDidMount() { | |
this.checkLogin(); | |
} | |
componentDidUpdate() { | |
this.checkLogin(); | |
} | |
checkLogin() { | |
this.isAuthenticate = false; | |
if(this.props.functionOfContainerWhichCheckLogin()) | |
this.isAuthenticate = true; | |
else | |
this.props.functionWhichGoToLogin(); | |
} | |
render() { | |
if(!this.isAuthenticate) { | |
return null; | |
} else { | |
return ( | |
<p> Admin </p> | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment