Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pages/admin/users/auth/simple/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@
:loading="loading"
type="submit"
class="w-full sm:w-fit"
:disabled="
!(validUsername && validEmail && username && email)
"
:disabled="!(validUsername && validEmail)"
>
{{ $t("users.admin.simple.inviteButton") }}
</LoadingButton>
Expand Down
14 changes: 7 additions & 7 deletions server/api/v1/admin/auth/invitation/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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";
import { SharedRegisterValidator } from "../../../auth/signup/simple.post";

const CreateInvite = CreateUserValidator.and({
expires: "Date",
isAdmin: "boolean = false",
}).configure(throwingArktype);
const CreateInvite = SharedRegisterValidator.partial()
.and({
expires: "string",
isAdmin: "boolean = false",
})
.configure(throwingArktype);

export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, [
Expand All @@ -16,8 +18,6 @@ export default defineEventHandler(async (h3) => {

const body = await readDropValidatedBody(h3, CreateInvite);

console.log(body);

const invitation = await prisma.invitation.create({
data: body,
});
Expand Down
18 changes: 7 additions & 11 deletions server/api/v1/auth/signup/simple.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { type } from "arktype";
import { randomUUID } from "node:crypto";
import { throwingArktype } from "~/server/arktype";

export const CreateUserValidator = type({
invitation: "string?", // Optional because we re-use this validator
export const SharedRegisterValidator = type({
username: "string >= 5",
email: "string.email",
});

const CreateUserValidator = SharedRegisterValidator.and({
invitation: "string",
password: "string >= 14",
"displayName?": "string | undefined",
}).configure(throwingArktype);
Expand All @@ -28,15 +31,8 @@ export default defineEventHandler<{

const user = await readValidatedBody(h3, CreateUserValidator);

const invitationId = user.invitation;
if (!invitationId)
throw createError({
statusCode: 401,
statusMessage: t("errors.auth.invalidInvite"),
});

const invitation = await prisma.invitation.findUnique({
where: { id: invitationId },
where: { id: user.invitation },
});
if (!invitation)
throw createError({
Expand Down Expand Up @@ -87,7 +83,7 @@ export default defineEventHandler<{
user: true,
},
}),
prisma.invitation.delete({ where: { id: invitationId } }),
prisma.invitation.delete({ where: { id: user.invitation } }),
]);

return linkMec.user;
Expand Down