Skip to content

Commit b19d2fc

Browse files
committed
refactor: remove user IP validation from AuthRouter and UsersRouter, default client IP to 'unknown' in UsersService
1 parent 3cd6eb9 commit b19d2fc

File tree

3 files changed

+4
-25
lines changed

3 files changed

+4
-25
lines changed

src/routes/v2/auth.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { BaseIsomerError } from "@root/errors/BaseError"
2-
31
const autoBind = require("auto-bind")
42
const express = require("express")
53

@@ -109,12 +107,6 @@ class AuthRouter {
109107
})
110108
const email = rawEmail.toLowerCase()
111109
const userIp = isSecure ? req.get("cf-connecting-ip") : req.ip
112-
if (!userIp) {
113-
throw new BaseIsomerError({
114-
status: 500,
115-
message: "No user IP found in the request",
116-
})
117-
}
118110
const userInfo = (
119111
await this.authService.verifyOtp({ email, otp, clientIp: userIp })
120112
).value

src/routes/v2/authenticated/users.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { attachReadRouteHandlerWrapper } from "@middleware/routeHandler"
1111

1212
import UserSessionData from "@classes/UserSessionData"
1313

14-
import { BaseIsomerError } from "@root/errors/BaseError"
1514
import DatabaseError from "@root/errors/DatabaseError"
1615
import { isError, RequestHandler } from "@root/types"
1716
import { nameAnonymousMethods } from "@root/utils/apm-utils"
@@ -86,12 +85,6 @@ export class UsersRouter {
8685
const parsedEmail = email.toLowerCase()
8786

8887
const userIp = isSecure ? req.get("cf-connecting-ip") : req.ip
89-
if (!userIp) {
90-
throw new BaseIsomerError({
91-
status: 500,
92-
message: "No user IP found in the request",
93-
})
94-
}
9588
return this.usersService
9689
.verifyEmailOtp(parsedEmail, otp, userIp)
9790
.andThen(() =>
@@ -152,12 +145,6 @@ export class UsersRouter {
152145
const userId = userSessionData.isomerUserId
153146

154147
const userIp = isSecure ? req.get("cf-connecting-ip") : req.ip
155-
if (!userIp) {
156-
throw new BaseIsomerError({
157-
status: 500,
158-
message: "No user IP found in the request",
159-
})
160-
}
161148
return this.usersService
162149
.verifyMobileOtp(mobile, otp, userIp)
163150
.andThen(() =>

src/services/identity/UsersService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ class UsersService {
273273
otp,
274274
findConditions,
275275
findErrorMessage,
276-
clientIp,
276+
clientIp = "unknown", // default to 'unknown' bucket when IP missing to ensure users are not locked out
277277
}: {
278278
otp: string | undefined
279279
findConditions: { email: string } | { mobileNumber: string }
280280
findErrorMessage: string
281-
clientIp: string
281+
clientIp?: string
282282
}) {
283283
if (!otp) {
284284
return errAsync(new BadRequestError("Empty OTP provided"))
@@ -391,7 +391,7 @@ class UsersService {
391391
/* eslint-enable @typescript-eslint/no-non-null-assertion */
392392
}
393393

394-
verifyEmailOtp(email: string, otp: string | undefined, clientIp: string) {
394+
verifyEmailOtp(email: string, otp: string | undefined, clientIp?: string) {
395395
const normalizedEmail = email.toLowerCase()
396396

397397
return this.verifyOtp({
@@ -405,7 +405,7 @@ class UsersService {
405405
verifyMobileOtp(
406406
mobileNumber: string,
407407
otp: string | undefined,
408-
clientIp: string
408+
clientIp?: string
409409
) {
410410
return this.verifyOtp({
411411
otp,

0 commit comments

Comments
 (0)