I am currently attempting to run
member.verify()
from within my loopback application, the email sends out absolutely fine except that the url is being formatted in the following way, on the email:-
http://https://example.api.com:port
The members.js has the following code in to send the email on creation of a new member:-
Member.afterRemote('create', function(context, member, next) {
console.log('Sending Verification Email');
var options = {
type: 'email',
to: member.email,
from: 'noreply@example.com',
subject: 'Thanks for registering.',
template: path.resolve(__dirname, '../../server/views/verify.ejs'),
redirect: 'https://' + config.host + '/login?verified=true',
user: member
};
member.verify(options, function(err) {
console.log('Verification Email sent:', member, options, err);
if (err){
next(err);
}else{
next();
}
});
});
The verify.ejs just contains:-
This is the html version of your email.
<strong><%= text %></strong>
Has anybody else had this issue or know how to resolve it?
Also does anybody know how to remove the port number from the end of the URL?
If you require any other information please let me know.
EDIT:-
I have found the following code inside the API's node_modules/loopback/common/models/user.js
var displayPort = (
(verifyOptions.protocol === 'http' && verifyOptions.port == '80') ||
(verifyOptions.protocol === 'https' && verifyOptions.port == '443')
) ? '' : ':' + verifyOptions.port;
var urlPath = joinUrlPath(
verifyOptions.restApiRoot,
userModel.http.path,
userModel.sharedClass.findMethodByName('confirm').http.path
);
verifyOptions.verifyHref = verifyOptions.verifyHref ||
verifyOptions.protocol +
'://' +
verifyOptions.host +
displayPort +
urlPath +
'?' + qs.stringify({
uid: '' + verifyOptions.user[pkName],
redirect: verifyOptions.redirect,
});
Is there any way I can overwrite this information?
Ok so I have managed to resolve this issue using the following:-
var options = {
type: 'email',
to: member.email,
from: 'noreply@clientplan.com',
subject: 'Thanks for registering.',
template: path.resolve(__dirname, '../../server/views/verify.ejs'),
redirect: 'https://client-plan-app.herokuapp.com/admin',
user: member,
protocol: 'https',
port : '443'
};
I have added the following lines to resolve this issue:-
protocol: 'https',
port : '443'