diff options
| author | rtkay123 <dev@kanjala.com> | 2026-02-22 13:02:35 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-02-22 13:02:35 +0200 |
| commit | 3fef60a3daf7d17dff22d815400e03f36e4128c9 (patch) | |
| tree | f806ab0df97fd314b8679eb483a8af9c8d344bfa /website/src/routes/welcome/+page.server.ts | |
| parent | 386ea2dc8271de95ac63864300f7198bdd445e23 (diff) | |
| download | sellershut-3fef60a3daf7d17dff22d815400e03f36e4128c9.tar.bz2 sellershut-3fef60a3daf7d17dff22d815400e03f36e4128c9.zip | |
feat(web): oauth redirect
Diffstat (limited to 'website/src/routes/welcome/+page.server.ts')
| -rw-r--r-- | website/src/routes/welcome/+page.server.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/website/src/routes/welcome/+page.server.ts b/website/src/routes/welcome/+page.server.ts new file mode 100644 index 0000000..503f361 --- /dev/null +++ b/website/src/routes/welcome/+page.server.ts @@ -0,0 +1,38 @@ +import { fail, redirect } from '@sveltejs/kit'; +import type { Actions, PageServerLoad } from './$types'; +import { profileSchema } from '$lib/schemas/profile'; + +export const actions: Actions = { + default: async ({ request, fetch }) => { + console.log("hello"); + const formData = await request.formData(); + const data = Object.fromEntries(formData); + + // 1. Zod Validation + const result = profileSchema.safeParse(data); + + if (!result.success) { + return fail(400, { + errors: result.error.flatten().fieldErrors, + data: data as Record<string, string> + }); + } + + // 2. Example: Check availability against your backend + // Replace this with your actual backend URL + const response = await fetch(`/api/check-username?u=${result.data.username}`); + const { available } = await response.json(); + + if (!available) { + return fail(400, { + errors: { username: ["This username is already taken"] }, + data: data as Record<string, string> + }); + } + + // 3. Success: Send to backend to create profile + // await fetch('...', { method: 'POST', body: JSON.stringify(result.data) }); + + throw redirect(303, '/dashboard'); + } +}; |
