Does email verification work out of the box?


#1

So I send an email with auto-generated verification link:
http://localhost:3000/#/verify-email/aLbO0TLtZy25aG9mLyNPLx__kFYxICRkyVJryEpuS39
But after I’ve clicked it it just redirects me to localhost and emails.0.verified remains false.
Do I need some voodoo here?


#2

You need to set the ROOT_URL environment variable to the domain name of your app. (see http://docs.meteor.com/#/full/meteor_absoluteurl)


#3

I don’t have a domain yet. I need it to work in develompent environment.


#4

development on localhost does not send e-mails. Either look into your server console where it prints the e-mail message, or start your local dev server with a valid MAIL_URL to actually send the messages.


#5

I don’t have problems with sending emails - I send them through Mailgun from localhost nicely.
I have problems with automatic setting of flag email.0.verified to true in user document. See my 1st post.


#6

Weird. I use the same mechanism here and it works as advertised without any magic.


#7

You just click the link and don’t do anything with Accounts.verifyEmail() and stuff? It just works?


#8

Yup, just tried it out.


#9

Does it work when you call Accounts.verifyEmail with the token manually?

I have a route for mail verifications set up myself with Accounts.verifyEmail in the action of the FlowRouter route definition.


#10

Yes, it does.
But I don’t understand - is it supposed to work out of the box or should I call Accounts.verifyEmail explicitly??


#11

I guess you have to call it yourself, http://docs.meteor.com/#/full/Accounts-onEmailVerificationLink says: 'An email verification token that can be passed to Accounts.verifyEmail'.

The docs don’t tell anything about it being handled automatically, as far as I know.


#12

@jamgold, do you agree?


#13

Well, I am not doing that in my code. I do not even have and onEmailVerification hook and it works.


#14

That’s very weird…


#15

Maybe you can try to replicate this in a stripped down Meteor app that only uses accounts-password?


#16

I am working on two apps for different clients. I am using an smtp service (smtp2go) for sending email. The verification email is being sent by development machine fine for both apps.
For one app, I am using the default verification, and it works. For the other I am using custom verification (overriding onCreateUser) , and it also works. But in both cases, I have to manually alter the link to point to my dev machine by changing the url from ‘localhost’ to the actual url of my development machine then pasting the url in the address of the browser. So it does work, but I’d like to know hw to set things up on the dev machine to automatically put my domain name in the URL in generates.
When deployed the url in the verification message is fine.


#17

It only works automatically if you are using accounts-ui. If you are crafting your own UI then you have to call Accounts.verifyEmail inside your onEmailVerificationLink. Essentially if you are catching the link, you have to handle it yourself. In fact, if you have the accounts-ui package loaded AND you have your own code for onEmailVerificationLink, it will throw an error (essentially - you can’t have both).


#18

That’s interesting. @jamgold, do you have accounts-ui?


#19

@avalanche1 yes, I use accounts-ui and also useraccounts package


#20

Ok, thanks to @wickedmuso this finally solved.