I send a verification email that has a link that brings a user back and sets verified to true.
Here is the code to set verify to true:
Template.main.created = function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message == 'Verify email link expired [403]') {
swal('This verification link has expired.')
}
} else {
swal('You have been verified!')
}
});
}
};
I get the the success message displayed when I first arrive, but whenever I go back to my main template after that I keep getting the error message.
I thought of creating a verify-email template and that the link somehow sends him there and then I call a timeout function that sends him back to the main but I think there must be an easier solution.
Also I want to offer to user the option to resend the verification email if it really is expired
{{ #if !Meteor.user().emails[0].verified }}
âsend verification mailâ (What function do I call here since the docs say i should send the mail from the server)
you can call a method to review the email of the user and if is not verified you send the email
Meteor.methods({
'sendVerificationEmail': function () {
var userId = this.userId;
if (!userId)
throw new Meteor.Error(402, 'no user login');
var user = Meteor.users.findOne({_id: userId, 'emails.0.verified': false});
if (user)
Accounts.sendVerificationEmail(userId, user.emails[0].address);
}
});
Thanks for the input, Iâll do that then, wasnât sure about the security threats since the docs say it should be sent from the server.
What about the verify token, is it a good idea to create a new template and verify the user there and then forbid access if the user is already verified, or is that too much?
put the method sendVerificationEmail on the server and the client never see him, to verify token you need to call Accounts.verifyEmail on the client, Might create a route that only verifies the userâs email and if it works you redirect to the successful verified email view
Accounts.verifyEmail is a function that call some method on the server, Meteor is responsible for security in this case
Iâve created a new template for the verify-email route but now it doesnât verify my email nor does it throws errors and just sends me to â/â. Guessing verifyEmail template never gets created.
Router.route('/verify-email/:token', function () {
this.render('verifyEmail');
})
Template.verifyEmail.created = function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message == 'Verify email link expired [403]') {
swal('Verification link has expired.')
}
} else {
swal('Address has been confirmed.')
}
});
}
};
Not sure why it doesnât work, problem with iron:router maybe?