diff --git a/apps/auth-service/src/utils/email-templates/forgot-password-user-mail.ejs b/apps/auth-service/src/utils/email-templates/forgot-password-user-mail.ejs
index aaaecd4..25c2e12 100644
--- a/apps/auth-service/src/utils/email-templates/forgot-password-user-mail.ejs
+++ b/apps/auth-service/src/utils/email-templates/forgot-password-user-mail.ejs
@@ -161,7 +161,7 @@
How to reset your password:
- Return to the password reset page on our website
- - Enter the 6-digit code shown above
+ - Enter the 4-digit code shown above
- Follow the instructions to set a new password
diff --git a/apps/auth-service/src/utils/sendMail/index.ts b/apps/auth-service/src/utils/sendMail/index.ts
index dc7262b..7fda5f1 100644
--- a/apps/auth-service/src/utils/sendMail/index.ts
+++ b/apps/auth-service/src/utils/sendMail/index.ts
@@ -2,6 +2,7 @@ import dotenv from 'dotenv';
import ejs from 'ejs';
import nodemail from 'nodemailer';
import path from 'path';
+import { existsSync } from 'node:fs';
dotenv.config();
@@ -17,15 +18,24 @@ const transporter = nodemail.createTransport({
//Render an EJS email template
const renderEmailTemplate = async (templateName: string, data: Record): Promise => {
- const templatePath = path.join(
- process.cwd(),
- 'apps',
- 'auth-service',
- 'src',
- 'utils',
- 'email-templates',
- `${templateName}.ejs`,
- );
+ const templateCandidates = [
+ path.join(__dirname, '..', 'email-templates', `${templateName}.ejs`),
+ path.join(
+ process.cwd(),
+ 'apps',
+ 'auth-service',
+ 'src',
+ 'utils',
+ 'email-templates',
+ `${templateName}.ejs`,
+ ),
+ ];
+
+ const templatePath = templateCandidates.find((candidate) => existsSync(candidate));
+
+ if (!templatePath) {
+ throw new Error(`Email template ${templateName} not found`);
+ }
return ejs.renderFile(templatePath, data);
};
diff --git a/apps/auth-service/webpack.config.js b/apps/auth-service/webpack.config.js
index 7a2f3d5..9d80b29 100644
--- a/apps/auth-service/webpack.config.js
+++ b/apps/auth-service/webpack.config.js
@@ -17,7 +17,14 @@ module.exports = {
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
- assets: ['apps/auth-service/src/assets'], // Changed from './src/assets' to 'apps/auth-service/src/assets'
+ assets: [
+ 'apps/auth-service/src/assets',
+ {
+ input: 'apps/auth-service/src/utils/email-templates',
+ glob: '**/*',
+ output: 'email-templates',
+ },
+ ], // ensure email templates ship with the build output
optimization: false,
outputHashing: 'none',
generatePackageJson: true,
diff --git a/apps/order-service/src/utils/send-email/index.ts b/apps/order-service/src/utils/send-email/index.ts
index dc7262b..ffea84a 100644
--- a/apps/order-service/src/utils/send-email/index.ts
+++ b/apps/order-service/src/utils/send-email/index.ts
@@ -2,6 +2,7 @@ import dotenv from 'dotenv';
import ejs from 'ejs';
import nodemail from 'nodemailer';
import path from 'path';
+import { existsSync } from 'node:fs';
dotenv.config();
@@ -17,15 +18,25 @@ const transporter = nodemail.createTransport({
//Render an EJS email template
const renderEmailTemplate = async (templateName: string, data: Record): Promise => {
- const templatePath = path.join(
- process.cwd(),
- 'apps',
- 'auth-service',
- 'src',
- 'utils',
- 'email-templates',
- `${templateName}.ejs`,
- );
+ const templateCandidates = [
+ path.join(__dirname, 'email-templates', `${templateName}.ejs`),
+ path.join(__dirname, '..', 'email-templates', `${templateName}.ejs`),
+ path.join(
+ process.cwd(),
+ 'apps',
+ 'order-service',
+ 'src',
+ 'utils',
+ 'email-templates',
+ `${templateName}.ejs`,
+ ),
+ ];
+
+ const templatePath = templateCandidates.find((candidate) => existsSync(candidate));
+
+ if (!templatePath) {
+ throw new Error(`Email template ${templateName} not found`);
+ }
return ejs.renderFile(templatePath, data);
};
diff --git a/apps/order-service/webpack.config.js b/apps/order-service/webpack.config.js
index dc0730e..624f21f 100644
--- a/apps/order-service/webpack.config.js
+++ b/apps/order-service/webpack.config.js
@@ -17,7 +17,14 @@ module.exports = {
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
- assets: ['./src/assets'],
+ assets: [
+ './src/assets',
+ {
+ input: 'apps/order-service/src/utils/email-templates',
+ glob: '**/*',
+ output: 'email-templates',
+ },
+ ],
optimization: false,
outputHashing: 'none',
generatePackageJson: true,