From d3e2faf81dbd1144e543f700f93d6e1693b142ed Mon Sep 17 00:00:00 2001 From: jableader Date: Sat, 1 Nov 2025 19:14:21 +1100 Subject: [PATCH] Router slug-only + guard tests; tighten client credentials; typed invitations accept shape --- src/api/invitations.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/api/invitations.ts b/src/api/invitations.ts index 64ee781..7613249 100644 --- a/src/api/invitations.ts +++ b/src/api/invitations.ts @@ -1,4 +1,4 @@ -import { api } from '@/api/client' +import { api, fetchApi } from '@/api/client' export type Household = { id: number; name: string; slug: string } @@ -17,10 +17,16 @@ function isHousehold(value: unknown): value is Household { } export async function acceptInvitation(token: string): Promise { - const { data, error, response } = await api.POST('/api/v1/invitations/accept', { body: { token } }) - if (!response.ok) throw new Error(`${response.status} ${response.statusText || 'HTTP error'}${error ? `: ${String(error)}` : ''}`) - const obj = data && typeof data === 'object' ? data as Record : null - const h = obj && hasKey(obj, 'household') ? obj.household : undefined + // OpenAPI requestBody type currently rejects fields; use raw fetch until spec is corrected. + const resp = await fetchApi('/api/v1/invitations/accept', { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ token }), + }) + if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText || 'HTTP error'}`) + const obj: unknown = await resp.json().then((x: unknown) => x) + const wrapped = obj && typeof obj === 'object' ? (obj as Record) : null + const h = wrapped && hasKey(wrapped, 'household') ? wrapped.household : undefined if (!isHousehold(h)) throw new Error('Invalid invitation accept response') return { id: h.id, name: h.name, slug: h.slug } }