Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit db19ca0

Browse files
committed
fix: solve problem of using mail's password from secrets
1 parent a4e1d4c commit db19ca0

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

api-service/api/src/configs/mailer.config.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ import nodemailer from 'nodemailer';
22
import fs from "fs";
33

44
const path = "/run/secrets/google_api_secret";
5-
let secretValue = "";
6-
7-
fs.readFile(path, 'utf8', (err, data) => {
8-
if (err) {
9-
console.error(`Error reading secret file: ${err.message}`);
10-
process.exit(1);
11-
}
12-
secretValue = data.trim();
13-
});
5+
const secretValue = fs.readFileSync(path, 'utf8').trim();
146

157
const config = {
168
service: 'gmail',
179
auth: {
18-
user: process.env.MAIL_USER,
10+
user: "chainvote.01@gmail.com",
1911
pass: secretValue
2012
}
2113
}

api-service/api/src/controllers/codes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ export async function generateCodeFor(req: Request, res: Response, next: NextFun
126126
// Divide the code in two parts
127127
const firstPart = code.substring(0, code.length/2);
128128
const secondPart = code.substring(code.length/2, code.length);
129+
129130
res.locals.code = StatusCodes.CREATED;
130131
res.locals.data = firstPart;
132+
133+
131134
const message = {
132135
from: 'ChainVote',
133136
to: res.locals.user.email,
@@ -137,6 +140,7 @@ export async function generateCodeFor(req: Request, res: Response, next: NextFun
137140
This is the other part of your code: <b>${secondPart}</b>
138141
`
139142
};
143+
140144
mailer.sendMail(message).then((info) => {
141145
return res.status(201).json(
142146
{

0 commit comments

Comments
 (0)