Skip to content

Commit

Permalink
Fix/make login response indistinguishable (#624)
Browse files Browse the repository at this point in the history
* feat: add extra logging for mail failure

* fix: always return 200 when attempting to retrieve otp

* chore: update logging for sms

* Fix: use logger.error
  • Loading branch information
alexanderleegs committed Mar 7, 2023
1 parent 0cb6308 commit 09cb4b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/routes/v2/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler")
const { FRONTEND_URL } = process.env
const { isSecure } = require("@utils/auth-utils")

const logger = require("@root/logger/logger")

const AUTH_TOKEN_EXPIRY_MS = parseInt(
process.env.AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS,
10
Expand Down Expand Up @@ -75,7 +77,14 @@ class AuthRouter {
async login(req, res) {
const { email: rawEmail } = req.body
const email = rawEmail.toLowerCase()
await this.authService.sendOtp(email)
try {
await this.authService.sendOtp(email)
} catch (err) {
// Log, but don't return so responses are indistinguishable
logger.error(
`Error occurred when attempting to login user ${email}: ${err}`
)
}
return res.sendStatus(200)
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/identity/SmsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SmsClient {
try {
await this.axiosClient.post(endpoint, sms)
} catch (err) {
logger.error(err)
logger.error(`Failed to send SMS to ${recipient}: ${err}`)
throw new Error("Failed to send SMS.")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/utilServices/MailClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MailClient {
},
})
} catch (err) {
logger.error(err)
logger.error(`Error occurred when sending email to ${recipient}: ${err}`)
throw new Error("Failed to send email.")
}
}
Expand Down

0 comments on commit 09cb4b9

Please sign in to comment.