Search code examples
reactjsmeteormeteor-accounts

Another cannot read props on callback


On the submit button I'm checking if the user is ok. But I can't access to my props on the callback.

Meteor.loginWithPassword({username:username}, password, function(error){
  if(!error){
    this.props.router.push('/');
  }
});


  constructor(props) {
    super(props)

    this.state = {
     username: '' ,
     password:'',
     errors: [],
     alertVisible: false
 };

My button:

<Button type='submit'  onClick={this.onClickLogIn.bind(this)}>Go</Button>

What should I do?


Solution

  • Solved:

    Meteor.loginWithPassword({username:username}, password, (error) => {
      if(!error){
        this.props.router.push('/ltr/dashboard');
      }
    });