Search code examples
meteoriron-routermeteor-accounts

Meteor accounts verifyEmail


I am trying to make email verification that with the accounts-password package work however I have come across a weird problem.

It seems the # in the email verification URL is causing an issue. The verification email URL usually looks like : http://localhost:3000/#/verify-email/cnaTqQSCgYAksIsFo5FgmV94NHwrfaM2g5GvdZDUMlN

When I click on this, nothing seems to happen; it just re-directs to localhost:3000/#

However when I remove the # (http://localhost:3000/verify-email/cnaTqQSCgYAksIsFo5FgmV94NHwrfaM2g5GvdZDUMlN) this seems to work perfectly.

The URL (http://localhost:3000/#/verify-email/cnaTqQSCgYAksIsFo5FgmV94NHwrfaM2g5GvdZDUMlN) comes from Meteor so it's not something I create.

Here are my routes and controllers (using iron-router)

Router.route('/verify-email/:_token', {
    controller : 'AccountController',
    action : 'verifyEmail'
});

AccountController = RouteController.extend({
    fastRender: true,
    data: function () {},
    onBeforeAction: function () {
        this.render('Loading');
        this.next();
    },

    verifyEmail: function() {
        var verificationToken = this.params._token;
        console.log(verificationToken);
        Accounts.verifyEmail(verificationToken,  function(error) {
           if (error) {
               console.log(error);
           } else {
               Router.go('/');
           }
        });

    }
});

Any help is appreciated.


Solution

  • The conflict might be connected to the accounts-password package together with iron:router as outlined here:

    ...add a server file that overrides the urls with # paths that Meteor creates, so that the Iron-Router can work:

    (function () {
        "use strict";
    
        Accounts.urls.resetPassword = function (token) {
            return Meteor.absoluteUrl('reset-password/' + token);
        };
    
        Accounts.urls.verifyEmail = function (token) {
            return Meteor.absoluteUrl('verify-email/' + token);
        };
    
        Accounts.urls.enrollAccount = function (token) {
            return Meteor.absoluteUrl('enroll-account/' + token);
        };
    
    })();
    

    Hope it will guide you in the right direction.