Meteor account email verify fails two ways
Asked Answered
T

2

6

I have email hooked up on my dev box, and get a verification email after creating a user. I can click on the included link, and it will bring me to my main page.

1) Clicking on the link seems to do some processing, because it redirects to /, but it does not change the verified flag on the user account.

2) It seems to ignore my Accounts.config setting, and only works when I explicitly call

token = Accounts.sendVerificationEmail(userId)

Details:

mrt --version
Meteorite version 0.6.11
Release 0.6.5.1

mrt list --using

standard-app-packages
preserve-inputs
less
coffeescript
iron-router
foundation
http
moment
email
spin
roles
accounts-base
accounts-password
accounts-ui

Server/lib/account.coffee

Accounts.config
  sendVerificationEmail: true          
  forbidClientAccountCreation: true

server method:

Meteor.startup ->
  create_user = (options) ->
    console.log('create_user: ' + options.username)
    userId = Accounts.createUser options

    # should not be necessary, but I get email only when included
    token = Accounts.sendVerificationEmail(userId)


  Meteor.methods({ create_user: create_user })  

After above called, mongo shows:

emails: [ { "address" : "[email protected]" , "verified" : false}]

and

email: { "verificationTokens" : [ { "token" : "N3sLEDMsutTbjxyzX" , "address" : "[email protected]" , "when" : 1.380616343673E12}]}

Get default email:

Hello,    
To verify your account email, simply click the link below.    
http://localhost:3000/#/verify-email/N3sLEDMsutTbjxyzX        
Thanks.    

Clicking above link gets me to:

http://localhost:3000/

But no changes to the mongo db.

I was expecting something pulled in by accounts-password processed /#/verify-email/N3sLEDMsutTbjxyzX and would update the user document.

accounts-base.js tries, with

match = window.location.hash.match(/^\#\/verify-email\/(.*)$/);

but the location hash is empty by this time.

Am I missing something where I need to manually set up routes? Is my use of iron router ruining things? Just in case,

Router.map ->
  this.route 'home',
    path: '/'

  this.route 'inboxes'
  this.route 'availability'
  this.route 'find-agent'
  this.route 'inbox-tour'
  this.route 'availability-tour'
  this.route 'find-agent-tour'

  this.route 'inbox', 
    path: '/inbox/:_id'
    data: () ->

      m = Messages.findOne this.params._id
      m._markRead()
      fixed = _.map m.history.versions, (msg) =>
        msg.left = (msg.author is 'offer')
        msg.body = msg.body.replace( /[\r\n]+/g, "<br>")
        msg
      m.history.versions = fixed
      Session.set  'messageVersions', fixed
      m

    waitOn: db.subscriptions.messages
    loadingTemplate: 'loading'
    notFoundTemplate: 'notFound'

  this.route 'register',
  this.route 'requested',
  this.route 'blog',
  this.route 'test',
  this.route 'aboutUs'        

Router.configure
  layout: 'layout'

  notFoundTemplate: 'notFound'

  loadingTemplate: 'loading'

  renderTemplates: 
    'footer': { to: 'footer' }
    'sidebar': { to: 'sidebar' }



  ### Commented to rule out this routine
  before: ->
    routeName = @context.route.name
    debugger

    # no need to check at these URLs
    #, etc 
    return  if _.include(["request", "passwordReset","register", "tour"], routeName)
    return  if _.intersection(routeName.split('-'), ["tour"]).length > 0
    return if routeName.indexOf('verify-email') != -'' 
    user = Meteor.user()
    unless user
      #@render (if Meteor.loggingIn() then @loadingTemplate else "/")
      if Meteor.loggingIn()
        console.log('still logging in, no user, to ' + @loadingTemplate)
        @render @loadingTemplate
        console.log('!render ' + @loadingTemplate + ' completed' )
      else
        console.log('no user, / from router over ' + @loadingTemplate)
        @render "home"
      @stop()
  ###

Thanks!

Tallyman answered 1/10, 2013 at 9:21 Comment(0)
B
3

I confirm, this is now perfectly working. Here is what I do once I'm redirect to the root of the application.

Read More: Verify an Email with Meteor Accounts.

// (client-side)
Template.Homepage.created = function() {
  if (Accounts._verifyEmailToken) {
    Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
      if (err != null) {
        if (err.message = 'Verify email link expired [403]') {
          console.log('Sorry this verification link has expired.')
        }
      } else {
        console.log('Thank you! Your email address has been confirmed.')
      }
    });
  }
};
Bode answered 25/8, 2014 at 13:24 Comment(0)
S
5

Apparently there is a known issue with iron router and URLs that have hashbangs in the path, as the one it is generated with the email :

https://github.com/EventedMind/iron-router/issues/3

I suggest you try implement the same solution as the user samhatoum says (careful that I think since he put the code on the extends method in RootController has changed for extend.

Sarracenia answered 3/10, 2013 at 23:14 Comment(3)
Thanks! I should have had a look there. Thought iron router was... iron. Never thought it would fail on such a baked in area of code. Especially considering there is already money behind it (meteor, not I-R). Will accept your answer shortly, just want to keep it on the attention list. And the issue itself on github seems unresolved.Tallyman
It seems that the author of the package thought it was already resolved, but then a couple of other users kept reporting the problem so guess it's not. I posted a comment on the issue thread to let the author know...Sarracenia
Hey guys, I think this should be fixed on the dev branch which will be released soon. Please post a bug on github if you still notice the issue on dev.Palpitant
B
3

I confirm, this is now perfectly working. Here is what I do once I'm redirect to the root of the application.

Read More: Verify an Email with Meteor Accounts.

// (client-side)
Template.Homepage.created = function() {
  if (Accounts._verifyEmailToken) {
    Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
      if (err != null) {
        if (err.message = 'Verify email link expired [403]') {
          console.log('Sorry this verification link has expired.')
        }
      } else {
        console.log('Thank you! Your email address has been confirmed.')
      }
    });
  }
};
Bode answered 25/8, 2014 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.