Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: log channel provider message id to aid debugging #1951

Merged
merged 4 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions backend/src/core/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Transaction } from 'sequelize/types'

export interface AuthService {
canSendOtp(email: string): Promise<void>
sendOtp(email: string, ipAddress: string): Promise<boolean>
sendOtp(email: string, ipAddress: string): Promise<void>
verifyOtp(input: VerifyOtpInput): Promise<boolean>
findOrCreateUser(email: string): Promise<User>
findUser(id: number): Promise<User>
Expand Down Expand Up @@ -210,10 +210,7 @@ export const InitAuthService = (redisService: RedisService): AuthService => {
* @param email
* @param ipAddress originating IP address that requests for OTP.
*/
const sendOtp = async (
email: string,
ipAddress: string
): Promise<boolean> => {
const sendOtp = async (email: string, ipAddress: string): Promise<void> => {
const otp = generateOtp()
const hashValue = await bcrypt.hash(otp, SALT_ROUNDS)
const hashedOtp: HashedOtp = {
Expand All @@ -224,7 +221,7 @@ export const InitAuthService = (redisService: RedisService): AuthService => {
await saveHashedOtp(email, hashedOtp)

const appName = config.get('APP_NAME')
return MailService.mailClient.sendMail({
void MailService.mailClient.sendMail({
from: config.get('mailFrom'),
recipients: [email],
subject: `One-Time Password (OTP) for ${appName}`,
Expand Down
10 changes: 9 additions & 1 deletion backend/src/email/services/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,15 @@ const sendEmail = async (
opts?: SendEmailOpts
): Promise<boolean> => {
try {
await MailService.mailClient.sendMail(mail, opts)
const serviceProviderMessageId = await MailService.mailClient.sendMail(
mail,
opts
)
logger.info({
message: 'Message sent to channel provider.',
nativeMessageId: mail.messageId,
serviceProviderMessageId,
})
} catch (e) {
logger.error({
message: 'Error while sending test email',
Expand Down
11 changes: 7 additions & 4 deletions shared/src/clients/mail-client.class/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ export default class MailClient {
this.configSet = configSet
}

public sendMail(input: MailToSend, option?: SendEmailOpts): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
public sendMail(
input: MailToSend,
option?: SendEmailOpts
): Promise<string | void> {
return new Promise<string>((resolve, reject) => {
const username = Math.random().toString(36).substring(2, 15) // random string
const xSmtpHeader: { [key: string]: any } = {
auth: {
Expand Down Expand Up @@ -83,11 +86,11 @@ export default class MailClient {
bcc: input.bcc,
}

this.mailer.sendMail(options, (err, _info) => {
this.mailer.sendMail(options, (err, info) => {
if (err !== null) {
reject(new Error(`${err}`))
} else {
resolve(true)
resolve(info.messageId)
}
})
})
Expand Down