Add verify middleware

This commit is contained in:
Owen Schwartz
2024-10-03 22:31:20 -04:00
parent e89ee4042a
commit a8f944fc78
17 changed files with 1230 additions and 40 deletions

View File

@@ -11,6 +11,8 @@ const createOrgSchema = z.object({
domain: z.string().min(1).max(255),
});
const MAX_ORGS = 5;
export async function createOrg(req: Request, res: Response, next: NextFunction): Promise<any> {
try {
const parsedBody = createOrgSchema.safeParse(req.body);
@@ -23,6 +25,16 @@ export async function createOrg(req: Request, res: Response, next: NextFunction)
);
}
const userOrgIds = req.userOrgs;
if (userOrgIds && userOrgIds.length > MAX_ORGS) {
return next(
createHttpError(
HttpCode.FORBIDDEN,
`Maximum number of organizations reached.`
)
);
}
const { name, domain } = parsedBody.data;
const newOrg = await db.insert(orgs).values({