lundi 27 février 2017

Meteor / Mongo - Check if user has a verified email address and redirect him

I need to find out whether the user who triggers a click. event has a verified email. In case "true" he should be redirected to another page, where he can call a server side method. In case "false" he should be redirected to a page, where he can click a button to resent a new verification link to him.

I tried to use some functions I found in other questions, but it didn´t work... Here is my code for the click. event and if function which does not work out:

"click. event": function(e){
  e.preventDefault();
   if (this.userId && Meteor.user().emails[0].verified)
   {
    Router.go('LinkToCallTheMethod');
     }; else 
     {
    console.log('Please verify email first');
    Router.go('LinkToResentVerificationLink');
     }
   });

The problem is that nothing happens. The user is not redirected even when I change the boolean in the emails[0].verified field to 'true' or 'false' (doesn´t matter, nothing happens), but I also do not receive any error code.

Therefore I think the problem is in the if(...&& Meteor.user().emails[0].verified). Is there another way to find out whether a email is verified?

Would be happy if anyone could help out. Thanks!

Aucun commentaire:

Enregistrer un commentaire