From 45746b1f0a0605d13d180fba360d560cc7a3bf3d Mon Sep 17 00:00:00 2001 From: Tim Hostetler <6970899+thostetler@users.noreply.github.com> Date: Sat, 7 Dec 2024 10:46:40 -0500 Subject: [PATCH] fix ip address parse bug (only in development) --- src/middleware.ts | 18 +++++------------- src/middlewares/botCheck.ts | 3 ++- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index fadd20af3..d76d47be1 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -113,10 +113,7 @@ const emitAnalytics = async (req: NextRequest): Promise => { // For abs/ routes we want to send emit an event to the link gateway if (path.startsWith('/abs')) { - const url = `${process.env.BASE_URL}/link_gateway${path.replace( - '/abs', - '', - )}`; + const url = `${process.env.BASE_URL}/link_gateway${path.replace('/abs', '')}`; log.debug({ path, url }, 'Emitting abs route event to link gateway'); try { @@ -133,7 +130,8 @@ const getIp = (req: NextRequest) => ( req.headers.get('X-Original-Forwarded-For') || req.headers.get('X-Forwarded-For') || - req.headers.get('X-Real-Ip') + req.headers.get('X-Real-Ip') || + '' ) .split(',') .shift() || 'unknown'; @@ -183,10 +181,7 @@ export async function middleware(req: NextRequest) { return loginMiddleware(req, res); } - if ( - path.startsWith('/user/account/register') || - path.startsWith('/user/forgotpassword') - ) { + if (path.startsWith('/user/account/register') || path.startsWith('/user/forgotpassword')) { return redirectIfAuthenticated(req, res); } @@ -194,10 +189,7 @@ export async function middleware(req: NextRequest) { return protectedRoute(req, res); } - if ( - path.startsWith('/user/account/verify/change-email') || - path.startsWith('/user/account/verify/register') - ) { + if (path.startsWith('/user/account/verify/change-email') || path.startsWith('/user/account/verify/register')) { return verifyMiddleware(req, res); } diff --git a/src/middlewares/botCheck.ts b/src/middlewares/botCheck.ts index db0c9bc99..2d6ea3fc6 100644 --- a/src/middlewares/botCheck.ts +++ b/src/middlewares/botCheck.ts @@ -15,7 +15,8 @@ const getIp = (req: NextRequest) => ( req.headers.get('X-Original-Forwarded-For') || req.headers.get('X-Forwarded-For') || - req.headers.get('X-Real-Ip') + req.headers.get('X-Real-Ip') || + '' ) .split(',') .shift() || 'unknown';