From 44764050216083d02fc0733dc62f1bf194286003 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Mon, 26 Jun 2017 13:48:24 -0400 Subject: [PATCH] change all email links to update protocol based on node env --- server/controllers/user.controller.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/controllers/user.controller.js b/server/controllers/user.controller.js index fb134f58..ac273d34 100644 --- a/server/controllers/user.controller.js +++ b/server/controllers/user.controller.js @@ -50,10 +50,11 @@ export function createUser(req, res, next) { return; } + const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; const mailOptions = renderEmailConfirmation({ body: { - domain: `http://${req.headers.host}`, - link: `http://${req.headers.host}/verify?t=${token}` + domain: `${protocol}://${req.headers.host}`, + link: `${protocol}://${req.headers.host}/verify?t=${token}` }, to: req.user.email, }); @@ -136,10 +137,11 @@ export function resetPasswordInitiate(req, res) { }); }, (token, user, done) => { + const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; const mailOptions = renderResetPassword({ body: { - domain: `http://${req.headers.host}`, - link: `http://${req.headers.host}/reset-password/${token}`, + domain: `${protocol}://${req.headers.host}`, + link: `${protocol}://${req.headers.host}/reset-password/${token}`, }, to: user.email, }); @@ -185,10 +187,11 @@ export function emailVerificationInitiate(req, res) { return; } + const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; const mailOptions = renderEmailConfirmation({ body: { - domain: `http://${req.headers.host}`, - link: `http://${req.headers.host}/verify?t=${token}` + domain: `${protocol}://${req.headers.host}`, + link: `${protocol}://${req.headers.host}/verify?t=${token}` }, to: user.email, }); @@ -310,10 +313,11 @@ export function updateSettings(req, res) { saveUser(res, user); + const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; const mailOptions = renderEmailConfirmation({ body: { - domain: `http://${req.headers.host}`, - link: `http://${req.headers.host}/verify?t=${token}` + domain: `${protocol}://${req.headers.host}`, + link: `${protocol}://${req.headers.host}/verify?t=${token}` }, to: user.email, });