2024-04-21 10:36:48 -07:00
|
|
|
import { AuthResponse } from "../../src/types";
|
2024-11-07 20:57:33 +01:00
|
|
|
import { logger } from "./logger";
|
2024-09-03 21:02:41 -03:00
|
|
|
import * as Sentry from "@sentry/node";
|
2024-09-04 15:57:57 -03:00
|
|
|
import { configDotenv } from "dotenv";
|
|
|
|
|
configDotenv();
|
2024-04-21 10:36:48 -07:00
|
|
|
|
2024-04-21 11:39:36 -07:00
|
|
|
let warningCount = 0;
|
|
|
|
|
|
2024-11-07 20:57:33 +01:00
|
|
|
export function withAuth<T, U extends any[]>(
|
|
|
|
|
originalFunction: (...args: U) => Promise<T>,
|
|
|
|
|
mockSuccess: T,
|
2024-04-21 10:36:48 -07:00
|
|
|
) {
|
|
|
|
|
return async function (...args: U): Promise<T> {
|
2024-08-12 14:20:41 -03:00
|
|
|
const useDbAuthentication = process.env.USE_DB_AUTHENTICATION === 'true';
|
|
|
|
|
if (!useDbAuthentication) {
|
2024-04-21 11:39:36 -07:00
|
|
|
if (warningCount < 5) {
|
2024-11-07 20:57:33 +01:00
|
|
|
logger.warn("You're bypassing authentication");
|
2024-04-21 11:39:36 -07:00
|
|
|
warningCount++;
|
|
|
|
|
}
|
2024-04-21 10:36:48 -07:00
|
|
|
return { success: true } as T;
|
|
|
|
|
} else {
|
2024-11-07 20:57:33 +01:00
|
|
|
return await originalFunction(...args);
|
2024-04-21 10:36:48 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|