change all email links to update protocol based on node env

This commit is contained in:
Cassie Tarakajian 2017-06-26 13:48:24 -04:00
parent 1dc0c22cb7
commit 4476405021

View file

@ -50,10 +50,11 @@ export function createUser(req, res, next) {
return; return;
} }
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
const mailOptions = renderEmailConfirmation({ const mailOptions = renderEmailConfirmation({
body: { body: {
domain: `http://${req.headers.host}`, domain: `${protocol}://${req.headers.host}`,
link: `http://${req.headers.host}/verify?t=${token}` link: `${protocol}://${req.headers.host}/verify?t=${token}`
}, },
to: req.user.email, to: req.user.email,
}); });
@ -136,10 +137,11 @@ export function resetPasswordInitiate(req, res) {
}); });
}, },
(token, user, done) => { (token, user, done) => {
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
const mailOptions = renderResetPassword({ const mailOptions = renderResetPassword({
body: { body: {
domain: `http://${req.headers.host}`, domain: `${protocol}://${req.headers.host}`,
link: `http://${req.headers.host}/reset-password/${token}`, link: `${protocol}://${req.headers.host}/reset-password/${token}`,
}, },
to: user.email, to: user.email,
}); });
@ -185,10 +187,11 @@ export function emailVerificationInitiate(req, res) {
return; return;
} }
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
const mailOptions = renderEmailConfirmation({ const mailOptions = renderEmailConfirmation({
body: { body: {
domain: `http://${req.headers.host}`, domain: `${protocol}://${req.headers.host}`,
link: `http://${req.headers.host}/verify?t=${token}` link: `${protocol}://${req.headers.host}/verify?t=${token}`
}, },
to: user.email, to: user.email,
}); });
@ -310,10 +313,11 @@ export function updateSettings(req, res) {
saveUser(res, user); saveUser(res, user);
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
const mailOptions = renderEmailConfirmation({ const mailOptions = renderEmailConfirmation({
body: { body: {
domain: `http://${req.headers.host}`, domain: `${protocol}://${req.headers.host}`,
link: `http://${req.headers.host}/verify?t=${token}` link: `${protocol}://${req.headers.host}/verify?t=${token}`
}, },
to: user.email, to: user.email,
}); });