diff --git a/lib/withAuth.ts b/lib/withAuth.ts index 0b963ebf1..2ba91db07 100644 --- a/lib/withAuth.ts +++ b/lib/withAuth.ts @@ -45,10 +45,10 @@ export async function getUserFromToken( const decoded = verifiedSignature; const userId = decoded.userId as string; // dynamically import newrelic - const newrelic = await import('newrelic'); + const newrelic = process.env.NODE_ENV === 'test' ? undefined : await import('newrelic'); if (!isLocal()) { - newrelic.addCustomAttribute && newrelic.addCustomAttribute('userId', userId); + newrelic?.addCustomAttribute && newrelic.addCustomAttribute('userId', userId); } await dbConnect();