Skip to content

Commit

Permalink
🐛 fix app breaking bug
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Dec 17, 2021
1 parent 5752872 commit 85c8075
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/middlewares/IsAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class IsAuth implements MiddlewareMethods {
}
}

export function setDiscordAUth(cad: cad) {
export function setDiscordAUth<T extends Pick<cad, "disabledFeatures"> | null = cad>(cad: T) {
const hasDiscordTokens = process.env["DISCORD_CLIENT_ID"] && process.env["DISCORD_CLIENT_SECRET"];
const isEnabled = !cad?.disabledFeatures?.includes("DISCORD_AUTH");

Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/middlewares/IsEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ const featuresRoute: Partial<Record<Feature, string>> = {
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!)) {
Expand Down

0 comments on commit 85c8075

Please sign in to comment.