diff --git a/modules/auth.js b/modules/auth.js index 2bb7740..b571f3c 100644 --- a/modules/auth.js +++ b/modules/auth.js @@ -12,7 +12,8 @@ const { sendMail, magicLinkHTML, otpText } = require('./email.js') const { updateUser, selectUser, getUserWL } = require('./db') const { claimOTP, redeemOTP } = require('./auth-otp') const { AuthorizationError, APIError, LOG_LEVEL_ERROR } = require('./errors') -const { PREFIX_APP_REVIEWER, PREFIX_DEV, PREFIX_MOBILE_SDK, PRODUCT_ATOM, PRODUCT_LOCUS } = require('../constants.js') +const { PREFIX_APP_REVIEWER, PREFIX_DEV, PREFIX_MOBILE_SDK, PRODUCT_ATOM, PRODUCT_LOCUS, PRODUCT_CLEARLAKE } = require('../constants.js') +const { capitalizeFirstLetter } = require('./utils') const { @@ -117,10 +118,16 @@ const loginUser = async ({ user, redirect, zone='utc', product = PRODUCT_ATOM, n // get user WL info const { rows = [] } = await getUserWL(user) + const DEFAULT_EMAIL = 'dev@eqworks.com' + const productSender = product === PRODUCT_CLEARLAKE + ? (process.env.CLEARLAKE_SENDER || DEFAULT_EMAIL) + : DEFAULT_EMAIL + const supportEmail = product === PRODUCT_CLEARLAKE + ? (process.env.CLEARLAKE_SUPPORT_EMAIL || DEFAULT_EMAIL) + : DEFAULT_EMAIL + // TODO: add logo in when email template has logo - let { sender, company } = rows[0] || {} - sender = sender || 'dev@eqworks.com' - company = company || 'EQ Works' + const { sender = productSender, company = 'EQ Works' } = rows[0] || {} const { prefix: userPrefix, api_access } = await getUserInfo({ email: user }) // Check if user has access to the requested product @@ -159,12 +166,12 @@ const loginUser = async ({ user, redirect, zone='utc', product = PRODUCT_ATOM, n text: otpText({ otp, ttl, company, product }), } : { text: otpText({ link, otp, ttl, company, product }), - html: magicLinkHTML({ link, otp, ttl, company, product }), + html: magicLinkHTML({ link, otp, ttl, company, product, supportEmail }), } return sendMail({ from: sender, to: user, - subject: `${product} (${company}) Login`, + subject: `${capitalizeFirstLetter(product)} (${company}) Login`, ...message, }) } diff --git a/modules/email.js b/modules/email.js index c593055..18c46a8 100644 --- a/modules/email.js +++ b/modules/email.js @@ -1,5 +1,6 @@ const nodemailer = require('nodemailer') const AWS = require('@aws-sdk/client-ses') +const { capitalizeFirstLetter } = require('./utils') module.exports.sendMail = async message => { @@ -27,7 +28,7 @@ module.exports.sendMail = async message => { return transport.sendMail(message) } -module.exports.magicLinkHTML = ({ link, otp, ttl, company, product }) => ` +module.exports.magicLinkHTML = ({ link, otp, ttl, company, product, supportEmail }) => ` @@ -35,7 +36,7 @@ module.exports.magicLinkHTML = ({ link, otp, ttl, company, product }) => ` - + ${capitalizeFirstLetter(product)} (${company}) Login Magic Link @@ -228,7 +229,7 @@ module.exports.magicLinkHTML = ({ link, otp, ttl, company, product }) => `
- ${product.toUpperCase()} (${company}) Login Magic Link + ${capitalizeFirstLetter(product)} (${company}) Login Magic Link
@@ -259,7 +260,7 @@ module.exports.magicLinkHTML = ({ link, otp, ttl, company, product }) => ` @@ -298,7 +299,7 @@ module.exports.magicLinkHTML = ({ link, otp, ttl, company, product }) => `
-

Welcome to ${product.toUpperCase()} (${company})

+

Welcome to ${capitalizeFirstLetter(product)} (${company})


-

Having an issue? Contact Us

+

Having an issue? Contact Us

@@ -321,7 +322,7 @@ module.exports.magicLinkHTML = ({ link, otp, ttl, company, product }) => ` ` module.exports.otpText = ({ link, otp, ttl, company, product }) => ` - Welcome to ${product.toUpperCase()} (${company})\n + Welcome to ${capitalizeFirstLetter(product)} (${company})\n ${link ? `Please login with the magic link ${link}\n` : ''} ${otp && ttl ? `Or manually enter: ${otp} \n This will expire after ${ttl}, and all previous email should be discarded.` : ''} diff --git a/modules/utils.js b/modules/utils.js new file mode 100644 index 0000000..dce2a86 --- /dev/null +++ b/modules/utils.js @@ -0,0 +1,13 @@ +/** + * Capitalizes the first letter of a string and makes the rest lowercase + * @param {string} str - The string to capitalize + * @returns {string} The capitalized string + */ +function capitalizeFirstLetter(str) { + if (!str) return '' + return str[0].toUpperCase() + str.slice(1).toLowerCase() +} + +module.exports = { + capitalizeFirstLetter, +} diff --git a/serverless.yml b/serverless.yml index c7eb547..d9f1521 100644 --- a/serverless.yml +++ b/serverless.yml @@ -32,6 +32,8 @@ provider: OTP_TTL: ${env:OTP_TTL} KEYWARDEN_VER: ${env:KEYWARDEN_VER} STAGE: ${opt:stage, self:provider.stage} + CLEARLAKE_SENDER: ${env:CLEARLAKE_SENDER} + CLEARLAKE_SUPPORT_EMAIL: ${env:CLEARLAKE_SUPPORT_EMAIL} REDIS_URI: # cloudformation functions to form redis://: "Fn::Join": [