Re-use validator from signup on invitation creation #108 (#111)

* fix: server side validation and client side validation for invitation creation

* fix: lint
This commit is contained in:
DecDuck
2025-06-08 11:59:00 +10:00
committed by GitHub
parent de438b93d5
commit 9f5a3b3976
3 changed files with 17 additions and 26 deletions

View File

@ -1,18 +1,14 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import { CreateUserValidator } from "../../../auth/signup/simple.post";
const CreateInvite = type({
isAdmin: "boolean?",
username: "string?",
email: "string.email?",
expires: "string.date.iso.parse",
const CreateInvite = CreateUserValidator.and({
expires: "Date",
isAdmin: "boolean = false",
}).configure(throwingArktype);
export default defineEventHandler<{
body: typeof CreateInvite.infer;
}>(async (h3) => {
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, [
"auth:simple:invitation:new",
]);
@ -20,6 +16,8 @@ export default defineEventHandler<{
const body = await readDropValidatedBody(h3, CreateInvite);
console.log(body);
const invitation = await prisma.invitation.create({
data: body,
});