diff options
| author | rtkay123 <dev@kanjala.com> | 2026-02-22 15:18:34 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-02-22 15:18:34 +0200 |
| commit | 3d4b23c53f203249b1d0c8e51d668f7b86dbaa6c (patch) | |
| tree | e3ec9dbe9216e0633338c1ba8960721d10b8bc69 /website/src/routes/welcome | |
| parent | 3fef60a3daf7d17dff22d815400e03f36e4128c9 (diff) | |
| download | sellershut-3d4b23c53f203249b1d0c8e51d668f7b86dbaa6c.tar.bz2 sellershut-3d4b23c53f203249b1d0c8e51d668f7b86dbaa6c.zip | |
Diffstat (limited to 'website/src/routes/welcome')
| -rw-r--r-- | website/src/routes/welcome/+page.server.ts | 81 | ||||
| -rw-r--r-- | website/src/routes/welcome/+page.svelte | 9 |
2 files changed, 55 insertions, 35 deletions
diff --git a/website/src/routes/welcome/+page.server.ts b/website/src/routes/welcome/+page.server.ts index 503f361..5a6e024 100644 --- a/website/src/routes/welcome/+page.server.ts +++ b/website/src/routes/welcome/+page.server.ts @@ -3,36 +3,53 @@ 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'); - } + default: async ({ request, fetch }) => { + console.log('hello'); + const formData = await request.formData(); + const data = Object.fromEntries(formData); + + const result = profileSchema.safeParse(data); + + if (!result.success) { + return fail(400, { + errors: result.error.flatten().fieldErrors, + data: data as Record<string, string>, + }); + } + + 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'); + }, +}; + +export const load = async ({ fetch, request }) => { + const res = await fetch('http://localhost:2210/me', { + headers: { + cookie: request.headers.get('cookie') || '', + }, + }); + + if (res.status === 401) throw redirect(302, '/login'); + + const userData = await res.json(); + + // if (userData.is_onboarded) { + // throw redirect(302, '/dashboard'); + // } + // + return { + user: userData, + }; }; diff --git a/website/src/routes/welcome/+page.svelte b/website/src/routes/welcome/+page.svelte index 863b69f..ade0837 100644 --- a/website/src/routes/welcome/+page.svelte +++ b/website/src/routes/welcome/+page.svelte @@ -1,6 +1,6 @@ <script lang="ts"> import { enhance } from '$app/forms'; - import type { ActionData } from './$types'; + import type { ActionData, PageData } from './$types'; type FormFailure = { errors: { username?: string[]; bio?: string[] }; @@ -8,7 +8,7 @@ }; const domain = 'sellershut.com'; - let { form }: { form: ActionData } = $props(); + let { form, data }: { form: ActionData; data: PageData } = $props(); const formError = $derived(form && 'errors' in form ? (form as FormFailure) : null); const errors = $derived(formError?.errors); @@ -30,6 +30,9 @@ $effect(() => { if (formError?.data?.username) username = formError.data.username; if (formError?.data?.bio) bio = formError.data.bio; + if (data) { + username = data.user.username; + } }); </script> @@ -128,7 +131,7 @@ id="email" name="email" type="email" - value="email@domain.com" + value={data.user.email} readonly tabindex="-1" class="flex-1 cursor-not-allowed border-none bg-transparent py-2.5 pr-4 pl-3 text-sm text-gray-500 outline-none focus:ring-0 md:text-base" |
