From 059d32e42c93fa0113e0bf253ab8bb432b3fa0b2 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Thu, 19 Mar 2026 10:10:20 -0400 Subject: [PATCH] feat: /user/{uuid} redirects to /user/{username} based off uuid --- .../routes/user/uuid/[uuid]/+page.server.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SharpbinV3.Client/src/routes/user/uuid/[uuid]/+page.server.ts diff --git a/SharpbinV3.Client/src/routes/user/uuid/[uuid]/+page.server.ts b/SharpbinV3.Client/src/routes/user/uuid/[uuid]/+page.server.ts new file mode 100644 index 0000000..63b3bbb --- /dev/null +++ b/SharpbinV3.Client/src/routes/user/uuid/[uuid]/+page.server.ts @@ -0,0 +1,23 @@ +import type { RequestEvent } from '@sveltejs/kit'; +import { error, redirect } from '@sveltejs/kit'; +import { apiUrl } from '$lib/server/api'; +import { getServerToken } from '$lib/utils/auth'; + +export const load = async ({ params, fetch, cookies }: RequestEvent) => { + const token = getServerToken(cookies); + const uuid = (params as Record).uuid; + + if (!uuid) throw error(404, 'User not found'); + + const res = await fetch(`${apiUrl}/api/user/uuid/${uuid}`, { + headers: token ? { Authorization: `Bearer ${token}` } : undefined + }); + + if (!res.ok) { + const { message } = await res.json().catch(() => ({})); + throw error(res.status, message ?? 'Request failed'); + } + + const { user } = (await res.json()) as { user: { username: string } }; + throw redirect(302, `/user/${encodeURIComponent(user.username)}`); +};