Files
pansy/web/src/lib/publicGarden.ts
T
steve 9968c06243
Build image / build-and-push (push) Successful in 8s
Public read-only share link (no login / no OIDC) (#41) (#43)
Per-garden public read-only link: unauthenticated GET /api/v1/public/gardens/:token (no requireAuth, no OIDC), owner-only enable/rotate/disable, and a /g/$token page rendering GardenCanvas read-only. Review fixes: redact plant owner ids, Cache-Control: no-store, 400 on malformed body, shared resetTransient store action.

Closes #41.

Co-authored-by: Steve Dudenhoeffer <[email protected]>
2026-07-19 06:18:31 +00:00

23 lines
897 B
TypeScript

// Public read-only garden data layer: the unauthenticated /full payload behind a
// share token. Shares the FullGarden shape with the editor's own load, so the
// public page can reuse toEditorObject / toEditorPlanting and GardenCanvas.
import { queryOptions, useQuery } from '@tanstack/react-query'
import { api } from './api'
import { fullGardenSchema, type FullGarden } from './objects'
export function publicGardenQueryOptions(token: string) {
return queryOptions({
queryKey: ['public-garden', token] as const,
queryFn: async (): Promise<FullGarden> =>
fullGardenSchema.parse(await api.get(`/public/gardens/${encodeURIComponent(token)}`)),
// A disabled/rotated token is a 404, not a transient failure — don't retry.
retry: false,
staleTime: 30_000,
})
}
export function usePublicGarden(token: string) {
return useQuery(publicGardenQueryOptions(token))
}