diff --git a/src/errors.ts b/src/errors.ts index 9964d96..90d0f03 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -4,7 +4,8 @@ export const errors = { BAD_AUTH: { code: 6003, message: "Bad authentication" }, NOT_FOUND: { code: 6004, message: "Not found" }, FORBIDDEN_DUE_TO_MISSING_PERMISSIONS: { code: 6005, message: "Forbidden due to missing permission(s)" }, - GOT_NO_DATABASE_DATA: { code: 7001, message: "Unexpectedly got no data from database" } + GOT_NO_DATABASE_DATA: { code: 7001, message: "Unexpectedly got no data from database" }, + FEATURE_DISABLED: { code: 7002, message: "This feature is disabled" } }; export const gatewayErrors = { diff --git a/src/routes/api/v1/users.ts b/src/routes/api/v1/users.ts index 7aa4dcb..aec59b0 100644 --- a/src/routes/api/v1/users.ts +++ b/src/routes/api/v1/users.ts @@ -12,6 +12,10 @@ router.post( body("username").isLength({ min: 3, max: 32 }).isAlphanumeric("en-US", { ignore: " _-" }), body("password").isLength({ min: 8, max: 1000 }), async (req, res) => { + if (process.env.DISABLE_ACCOUNT_CREATION === "true") { + return res.status(403).json({ ...errors.FEATURE_DISABLED }); + } + const validationErrors = validationResult(req); if (!validationErrors.isEmpty()) { return res.status(400).json({ ...errors.INVALID_DATA, errors: validationErrors.array() });