Reputation: 77
I am trying to make an email verification in my project using this tutorial: https://themeteorchef.com/tutorials/sign-up-with-email-verification
I've got method:
//server/methods/send-email.js
import { Meteor } from 'meteor/meteor';
import { Email } from 'meteor/email';
Meteor.methods({
sendVerificationLink() {
let userId = Meteor.userId();
if ( userId ) {
console.log("Email has been sent");
return Accounts.sendVerificationEmail( userId );
}
}
});
And call this method on client side:
//client/form.js
handleSubmit = () => {
this.validateField('phone', this.state.phone)
if (this.state.formValid) {
this.update_User({phone: this.state.phone});
}
Meteor.call( 'sendVerificationLink', ( error, response ) => {
if ( error ) {
console.log(error);
} else {
console.log("- There is no errors in Meteor.call -");
}
});
}
I am getting an email with link. But when I go this link, nothing happens. Meteor.user().emails[ 0 ].verified - doesn't become true.
{Meteor.user().emails[ 0 ].verified ? <div>Success</div> : <div>Failed</div>}
I don't get the Success text.
I've tried this:
import { Meteor } from 'meteor/meteor';
Accounts.emailTemplates.siteName = "name";
Accounts.emailTemplates.from = "name<[email protected]>";
Accounts.emailTemplates.verifyEmail = {
subject() {
return "[name] Verify Your Email Address";
},
text( user, url ) {
let emailAddress = user.emails[0].address,
urlWithoutHash = url.replace( '#/', '' ),
supportEmail = "[email protected]",
emailBody = `To verify your email address (${emailAddress}) visit the following link:\n\n${urlWithoutHash}\n\n If you did not request this verification, please ignore this email. If you feel something is wrong, please contact our support team: ${supportEmail}.`;
return emailBody;
}
};
Accounts.onEmailVerificationLink = function() {
console.log("Verified");
user.emails[0].verified = true;
}
But it seems I'm doing something wrong.
I am not very experienced in Meteor / backend... So I really hope to find some help here. Imagine cat looking deeply into your soul from "Puss in Boots" movie. That's me right now))
Upvotes: 2
Views: 1222
Reputation: 644
Like Deepak suggested, in react router that would be something like:
<Route exact path='/reset-password/:token' component={ResetPasswordPage} />
<Route exact path='/verify-email/:token' component={VerifyEmailPage} />
and the VerifyEmailPage could look like:
import React, { Component } from 'react'
import { Accounts } from 'meteor/accounts-base'
export default class VerifyEmailPage extends Component {
componentDidMount () {
const token = this.props.match.params.token
Accounts.verifyEmail(token, (err) => {
if (err) {
toastr.error('Could not verify email!', err.reason)
} else {
toastr.success('Email confirmed successfully!')
this.props.history.push('/feeds')
}
})
}
render () {
return (
<div>{''}</div>
)
}
}
Upvotes: 4
Reputation: 644
How about you remove the "return" from
return Accounts.sendVerificationEmail( userId )
and try again.
Upvotes: 2
Reputation: 308
You need to setup a route where you can get and verify the verification token.
Something like what they have done here, in the tutorial that you are following.
Basically, get the verification token on the frontend, call the Account method Accounts.verifyEmail
with verification token as parameter.
Upvotes: 2