Added ability to disable signups through environment variable

This commit is contained in:
Dries Augustyns
2024-08-03 21:34:23 +02:00
parent d0db0bee85
commit b1abcf06dd
3 changed files with 10 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@ export const JWT_SECRET = validateEnv("JWT_SECRET");
export const NODE_ENV = validateEnv<"development" | "production">("NODE_ENV", "production");
export const REDIS_URL = validateEnv("REDIS_URL");
export const DISABLE_SIGNUPS = validateEnv<"true" | "false">("DISABLE_SIGNUPS", "false") === "true";
// URLs
export const API_URI = validateEnv("API_URI", "http://localhost:4000");
+8
View File
@@ -1,6 +1,7 @@
import { Controller, Get, Post } from "@overnightjs/core";
import { UserSchemas, UtilitySchemas } from "@plunk/shared";
import type { Request, Response } from "express";
import { DISABLE_SIGNUPS } from "../app/constants";
import { prisma } from "../database/prisma";
import { NotAllowed, NotFound } from "../exceptions";
import { jwt } from "../middleware/auth";
@@ -47,6 +48,13 @@ export class Auth {
@Post("signup")
public async signup(req: Request, res: Response) {
if (DISABLE_SIGNUPS) {
return res.json({
success: false,
data: "Signups are currently disabled",
});
}
const { email, password } = UserSchemas.credentials.parse(req.body);
const user = await UserService.email(email);