2

I've got some code I want to run after the user verifies their email.

Where would I put that?

The only place I can think is a redirected route, but that's a bit hacky, and relies on the user waiting for the redirect to happen. I'm using iron-router.

This was my first attempt, but the recalculate function is server-side.

AccountsTemplates.configureRoute('verifyEmail', {
  redirect: function(){
    var user = Meteor.user();
    if (user) {
      user.recalculateSignUpReputation();
      Router.go('home');
    }
  }
});

Here's a solution observing a cursor but that seems like overkill. I'd prefer an event. Solution #1 didn't work for me.

Community
  • 1
  • 1
Michael Cole
  • 15,473
  • 7
  • 79
  • 96
  • Couldn't you put it directly in the email verification route? i.e. the user clicks the link from their email, and when that route is executed on your site, you trigger whatever action is necessary? – Brett McLain Jan 22 '16 at 04:28
  • @BrettMcLain UserAccounts/AccountsTemplates is managing that route, unless I'm mistaken. What do you mean? – Michael Cole Jan 22 '16 at 04:43
  • How about using [matb33:collection-hooks](https://atmospherejs.com/matb33/collection-hooks) and hooking updates to the user object? You could watch for the `verified` flag changing from false to true. – Michel Floyd Jan 22 '16 at 06:21

1 Answers1

0

thanks for the comments. I ended up doing this.

AccountsTemplates.configureRoute('verifyEmail', {
  redirect: function(){
    var user = Meteor.user();
    if (user) {
      Meteor.call('recalculateSignUpReputation');
      Router.go('home');
    }
  }
});

It works client side, and makes a call to the server-side code. Not awesome, but works. If you have a different/better way, I'll mark it the correct answer.

Michael Cole
  • 15,473
  • 7
  • 79
  • 96