diff --git a/packages/api/src/middlewares/IsAuth.ts b/packages/api/src/middlewares/IsAuth.ts index eede06551..e37a5e73b 100644 --- a/packages/api/src/middlewares/IsAuth.ts +++ b/packages/api/src/middlewares/IsAuth.ts @@ -92,7 +92,7 @@ export class IsAuth implements MiddlewareMethods { } } -export function setDiscordAUth(cad: cad) { +export function setDiscordAUth | null = cad>(cad: T) { const hasDiscordTokens = process.env["DISCORD_CLIENT_ID"] && process.env["DISCORD_CLIENT_SECRET"]; const isEnabled = !cad?.disabledFeatures?.includes("DISCORD_AUTH"); @@ -101,7 +101,7 @@ export function setDiscordAUth(cad: cad) { } if (isEnabled && !hasDiscordTokens) { - return { ...cad, disabledFeatures: [...cad.disabledFeatures, "DISCORD_AUTH"] }; + return { ...cad, disabledFeatures: [...(cad?.disabledFeatures ?? []), "DISCORD_AUTH"] }; } return cad; diff --git a/packages/api/src/middlewares/IsEnabled.ts b/packages/api/src/middlewares/IsEnabled.ts index a644d7c3c..b647a137c 100644 --- a/packages/api/src/middlewares/IsEnabled.ts +++ b/packages/api/src/middlewares/IsEnabled.ts @@ -17,15 +17,16 @@ const featuresRoute: Partial> = { export class IsEnabled implements MiddlewareMethods { async use(@Req() req: Req) { const cad = setDiscordAUth( - (await prisma.cad.findFirst({ + await prisma.cad.findFirst({ select: { id: true, disabledFeatures: true, }, - })) as any, + }), ); - for (const feature of cad.disabledFeatures) { + const disabledFeatures = cad?.disabledFeatures ?? []; + for (const feature of disabledFeatures) { const route = featuresRoute[feature as Feature]; if (req.originalUrl.includes(route!) || req.baseUrl.includes(route!)) {