add code signup to external api
deploy / build-and-deploy (push) Successful in 19s

This commit is contained in:
bytedream committed 2026-10-30 10:45:24 +01:00
1 parent f2ca4747a6
commit 0fc0024cb6
2 files changed
+32 -20

No files matched your search

+7 -4
View File
@@ -167,24 +167,27 @@
// Geburtstag im YYYY-MM-DD Format
"birthday": string,
// Telefonnummer des Spielers
"phone": string,
"phone": string | null,
// Minecraft-Username
"username": string,
// Minecraft-UUID mit Bindestrichen
"uuid": string,
// Minecraft-Edition
"edition": "java" | "bedrock"
"edition": "java" | "bedrock",
// Einladungscode einer direkten Einladung (optional)
"code": string | null | undefined
}
```
##### Response Codes
| http code | beschreibung |
| --------- | ------------------------------------------ |
| --------- | ----------------------------------------------------------------------------------------------- |
| 201 | Der User wurde erstellt |
| 400 | Der Request Body ist falsch |
| 401 | Es wurde ein falsches API Secret angegeben |
| 409 | Username oder UUID existiert bereits |
| 404 | Der Einladungscode existiert nicht |
| 409 | Der Einladungscode wurde bereits verwendet oder der User (Username oder UUID) existiert bereits |
</details>
+25 -16
View File
@@ -5,39 +5,48 @@ import { externalApi } from '../_api.ts';
export const POST = externalApi({
auth: true,
input: z.object({
firstname: z.string().trim().min(1),
lastname: z.string().trim().min(1),
firstname: z.string().trim(),
lastname: z.string().trim(),
birthday: z.string().date(),
phone: z.string().trim(),
username: z.string().trim().min(1),
phone: z.string().trim().nullable(),
username: z.string().trim(),
uuid: z.string().uuid(),
edition: z.enum(['java', 'bedrock'])
edition: z.enum(['java', 'bedrock']),
code: z.string().nullish()
}),
handler: async ({ input }) => {
if (input.code) {
const directSignup = await db.getDirectSignupByCode({ code: input.code });
// check if direct signup code exists
if (!directSignup) return new Response(null, { status: 404 });
// check if direct signup code was already used
else if (directSignup.user) return new Response(null, { status: 409 });
}
const existing = await db.existsUser({
username: input.username,
uuid: input.uuid
});
// check if user is already registered
if (existing) return new Response(null, { status: 409 });
if (existing) {
return new Response(JSON.stringify({ error: 'User with this username or uuid already exists' }), {
status: 409,
headers: {
'Content-Type': 'application/json'
}
});
}
await db.addUser({
await db.transaction(async (tx) => {
const user = await tx.addUser({
firstname: input.firstname,
lastname: input.lastname,
birthday: input.birthday,
telephone: input.phone || null,
telephone: input.phone,
username: input.username,
edition: input.edition,
uuid: input.uuid
});
if (input.code) {
await tx.setDirectSignupUser({ code: input.code, userId: user.id });
}
});
return new Response(null, { status: 201 });
}
});