Hy,
To manage redirection of the user, I use this code
export class Home extends React.Component {
constructor(props, context){
super(props, context);
this.State = {};
}getChildContext() {
return { muiTheme: getMuiTheme(baseTheme) };
}ManageAuthentication(){
if (!this.props.isAuthenticated) {
var loggedInUser = this.props.userId; let currentUser = this.props.currentUser; if (currentUser.profile.role !== 'user') { if (currentUser.profile.role === 'pro') { let exist = Roles.userIsInRole(loggedInUser, ['pro'], 'typeOfUser' ); if (!exist) {Meteor.call('addRole',loggedInUser, 'pro');}; Router.browserHistory.push('/EspaceProfessional'); } else if (currentUser.profile.role === 'admin') { let exist = Roles.userIsInRole(loggedInUser, ['admin'], 'typeOfUser' ); if (!exist) {Meteor.call('addRole',loggedInUser, 'admin');}; Router.browserHistory.push('/EspaceAdmin'); }else{ Router.browserHistory.push('/log'); }; }else if (currentUser.profile.role === 'user') { let exist = Roles.userIsInRole(loggedInUser, ['user'], 'typeOfUser' ); if (!exist) {Meteor.call('addRole',loggedInUser, 'user')}; return <div>{this.props.children}</div>; }; }else{ Router.browserHistory.push('/log'); };
}
render(){
if (!this.props && !this.props.isAuthenticated || !this.props.currentUser && !this.props.isAuthenticated) {
return
wait…
<CircularProgress size={119} thickness={7} style={{margin: 10.5}} />
}return ( <Grid fluid> <Row className="show-grid" > <Col xs={12} sm={12} md={12} lg={12} style={Styles.col} > <Nav /> </Col> <Col xs={12} sm={12} md={12} lg={12} style={Styles.col}> {this.ManageAuthentication()} </Col> </Row> </Grid> );
}
};Home.childContextTypes = {
muiTheme: React.PropTypes.object.isRequired,
};export default withTracker(props => {
return {
isAuthenticated: Meteor.userId() === null,
currentUser: Meteor.user(),
userId: Meteor.userId(),
};
})(Home);
How can you suggest me to improve it (it’s slow)?
what’s the best way to manage authentication ?
Thank’s