adds email confirmation

This commit is contained in:
Christian Beutel
2025-04-11 14:13:18 +02:00
parent 72d3428d5f
commit 5790da2317
14 changed files with 85 additions and 6 deletions

View File

@@ -1,16 +1,24 @@
import { env } from '$env/dynamic/public';
import { UserCreateSchema } from '$lib/models/api/user_schema';
import type { User } from '$lib/models/user';
import { pb } from '$lib/pocketbase';
import { Collection, create, handleError } from '$lib/util/api_util';
import { json, type RequestEvent } from '@sveltejs/kit';
import { ClientResponseError } from 'pocketbase';
export async function PUT(event: RequestEvent) {
if (env.PUBLIC_DISABLE_SIGNUP === "true") {
throw new ClientResponseError({ status: 401, response: { messgage: "Forbidden" } })
}
try {
if (env.PUBLIC_DISABLE_SIGNUP === "true") {
throw new ClientResponseError({ status: 401, response: { messgage: "Forbidden" } })
}
const r = await create<User>(event, UserCreateSchema, Collection.users)
const data = await event.request.json();
const safeData = UserCreateSchema.parse(data);
const r = await pb.collection(Collection.users).create<User>(safeData)
await pb.collection('users').requestVerification(safeData.email);
return json(r);
} catch (e: any) {