diff --git a/server/lib/readConfigFile.ts b/server/lib/readConfigFile.ts index 421a7028..5bce0db1 100644 --- a/server/lib/readConfigFile.ts +++ b/server/lib/readConfigFile.ts @@ -214,21 +214,6 @@ export const configSchema = z no_reply: z.string().email().optional() }) .optional(), - users: z.object({ - server_admin: z.object({ - email: z - .string() - .email() - .optional() - .transform(getEnvOrYaml("USERS_SERVERADMIN_EMAIL")) - .pipe(z.string().email()) - .transform((v) => v.toLowerCase()), - password: passwordSchema - .optional() - .transform(getEnvOrYaml("USERS_SERVERADMIN_PASSWORD")) - .pipe(passwordSchema) - }) - }), flags: z .object({ require_email_verification: z.boolean().optional(), diff --git a/server/middlewares/rateLimit.ts b/server/middlewares/rateLimit.ts index 19eac8bb..8b92f5f3 100644 --- a/server/middlewares/rateLimit.ts +++ b/server/middlewares/rateLimit.ts @@ -7,13 +7,16 @@ import config from "@server/lib/config"; import { RedisStore } from "rate-limit-redis"; import redisManager from "@server/db/redis"; -export let rateLimitStore: Store = new MemoryStore(); -if (config.getRawConfig().flags?.enable_redis) { - const client = redisManager.client!; - rateLimitStore = new RedisStore({ - sendCommand: async (command: string, ...args: string[]) => - (await client.call(command, args)) as any - }); +export function createStore(): Store { + let rateLimitStore: Store = new MemoryStore(); + if (config.getRawConfig().flags?.enable_redis) { + const client = redisManager.client!; + rateLimitStore = new RedisStore({ + sendCommand: async (command: string, ...args: string[]) => + (await client.call(command, args)) as any + }); + } + return rateLimitStore; } export function rateLimitMiddleware({ @@ -44,7 +47,7 @@ export function rateLimitMiddleware({ createHttpError(HttpCode.TOO_MANY_REQUESTS, message) ); }, - store: rateLimitStore + store: createStore() }); } else { return rateLimit({ @@ -57,7 +60,8 @@ export function rateLimitMiddleware({ return next( createHttpError(HttpCode.TOO_MANY_REQUESTS, message) ); - } + }, + store: createStore() }); } } diff --git a/server/routers/external.ts b/server/routers/external.ts index 939743ce..b0980fa5 100644 --- a/server/routers/external.ts +++ b/server/routers/external.ts @@ -32,7 +32,7 @@ import { verifyIsLoggedInUser, verifyClientAccess, verifyApiKeyAccess, - rateLimitStore, + createStore, } from "@server/middlewares"; import { verifyUserHasAction } from "../middlewares/verifyUserHasAction"; import { ActionsEnum } from "@server/auth/actions"; @@ -784,7 +784,7 @@ authRouter.post( const message = `You can only request an email verification code ${3} times every ${15} minutes. Please try again later.`; return next(createHttpError(HttpCode.TOO_MANY_REQUESTS, message)); }, - store: rateLimitStore + store: createStore() }), auth.requestEmailVerificationCode ); @@ -805,7 +805,7 @@ authRouter.post( const message = `You can only request a password reset ${3} times every ${15} minutes. Please try again later.`; return next(createHttpError(HttpCode.TOO_MANY_REQUESTS, message)); }, - store: rateLimitStore + store: createStore() }), auth.requestPasswordReset ); @@ -825,7 +825,7 @@ authRouter.post( const message = `You can only request an email OTP ${10} times every ${15} minutes. Please try again later.`; return next(createHttpError(HttpCode.TOO_MANY_REQUESTS, message)); }, - store: rateLimitStore + store: createStore() }), resource.authWithWhitelist );