adds email confirmation
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { Collection } from "$lib/util/api_util";
|
||||
import { error, type ServerLoad } from "@sveltejs/kit";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
|
||||
export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
|
||||
if (!params.token) {
|
||||
error(400, "Invalid token")
|
||||
}
|
||||
|
||||
try {
|
||||
await pb.collection(Collection.users).confirmVerification(params.token)
|
||||
} catch (e) {
|
||||
if (e instanceof ClientResponseError) {
|
||||
error(400, e.message);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { _ } from "svelte-i18n";
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{$_("email-verified")} | wanderer</title>
|
||||
</svelte:head>
|
||||
<main class="flex justify-center items-start">
|
||||
<div
|
||||
class="max-w-md border border-input-border rounded-xl p-8 flex flex-col justify-center items-center gap-4 w-[28rem] mt-8"
|
||||
>
|
||||
<i class="fa fa-check-circle text-emerald-400 text-7xl"></i>
|
||||
<h4 class="text-xl font-semibold">{$_("email-verified")}</h4>
|
||||
<div class="space-y-6 w-80">
|
||||
<p class="text-center">
|
||||
Thank you, your email was verified. Enjoy using wanderer!
|
||||
</p>
|
||||
</div>
|
||||
<a class="btn-primary mt-4" href="/">{$_("home")}</a>
|
||||
</div>
|
||||
</main>
|
||||
Reference in New Issue
Block a user