Does email verification work out of the box?

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?

1 Like

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

2 Likes

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

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.

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.

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

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

Yup, just tried it out.

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.

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

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.

@jamgold, do you agree?

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

That’s very weird…

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

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.

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).

1 Like

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

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

Ok, thanks to @wickedmuso this finally solved.