From 505434a2d8577419b4b723212939171675e2134a Mon Sep 17 00:00:00 2001 From: DragonDuck24 Date: Thu, 5 Feb 2026 19:09:34 -0600 Subject: [PATCH] inquiries and claims --- src/lib/auth/index.server.ts | 12 + .../custom/claim-item-dialog.svelte | 82 ++++++ .../components/custom/edit-item-dialog.svelte | 147 ++++++++++ .../custom/image-upload/image-upload.svelte | 7 +- .../custom/inquire-item-dialog.svelte | 95 +++++++ src/lib/components/custom/item-listing.svelte | 35 ++- .../custom/submit-item-dialog.svelte | 7 +- src/lib/db/items.remote.ts | 4 - src/lib/types/inquiries.server.ts | 16 +- src/lib/types/{item.d.ts => item.server.ts} | 3 + src/routes/+layout.svelte | 15 +- src/routes/account/+page.svelte | 10 + src/routes/items/+page.server.ts | 265 +++++++++++++++--- src/routes/items/+page.svelte | 64 ++++- 14 files changed, 686 insertions(+), 76 deletions(-) create mode 100644 src/lib/components/custom/claim-item-dialog.svelte create mode 100644 src/lib/components/custom/edit-item-dialog.svelte create mode 100644 src/lib/components/custom/inquire-item-dialog.svelte rename src/lib/types/{item.d.ts => item.server.ts} (79%) create mode 100644 src/routes/account/+page.svelte diff --git a/src/lib/auth/index.server.ts b/src/lib/auth/index.server.ts index fc2fcf8..f7a7c50 100644 --- a/src/lib/auth/index.server.ts +++ b/src/lib/auth/index.server.ts @@ -3,6 +3,7 @@ import bcrypt from 'bcrypt'; import sql from '$lib/db/db.server'; import { type Cookies, error } from '@sveltejs/kit'; import jwt from 'jsonwebtoken'; +import type { inquiryTokenPayload } from '$lib/types/inquiries.server'; export function setJWTCookie(cookies: Cookies, user: User) { const payload = { @@ -25,6 +26,17 @@ export function setJWTCookie(cookies: Cookies, user: User) { cookies.set('jwt', JWT, { maxAge, path: '/', httpOnly: false, secure }); } +export function createInquiryToken(payload: inquiryTokenPayload) { + if (process.env.JWT_SECRET === undefined) { + throw Error('JWT_SECRET not defined'); + } + if (process.env.BASE_URL === undefined) { + throw Error('BASE_URL not defined'); + } + + return jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: '30d' }); +} + export function verifyJWT(cookies: Cookies): UserPayload { const JWT = cookies.get('jwt'); if (!JWT) throw error(403, 'Unauthorized'); diff --git a/src/lib/components/custom/claim-item-dialog.svelte b/src/lib/components/custom/claim-item-dialog.svelte new file mode 100644 index 0000000..a255926 --- /dev/null +++ b/src/lib/components/custom/claim-item-dialog.svelte @@ -0,0 +1,82 @@ + + + + + + Claim Item + + Only submit this if you are sure the item is yours.
Claiming the item will remove it from public display. +
+
+ +
+ +
+ + {#if item?.image} + Lost item + {:else} +
+ +
+ + +
+

No image available

+
+ {/if} +
+
{item?.description}
+ {#if item?.foundLocation} +
+ +
{item?.foundLocation}
+
+ {/if} +
+
+ + + + Your Email * + + + +
+ + + + Cancel + + + +
+
+
+ + diff --git a/src/lib/components/custom/edit-item-dialog.svelte b/src/lib/components/custom/edit-item-dialog.svelte new file mode 100644 index 0000000..f4d9d87 --- /dev/null +++ b/src/lib/components/custom/edit-item-dialog.svelte @@ -0,0 +1,147 @@ + + + + + + Manage Item + + It will be updated immediately. + + + +
+
+ + + + + + + Description * + +