mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-24 05:46:39 +00:00
Add verify middleware
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user