Public read-only share link (no login / no OIDC) (#41) (#43)
Build image / build-and-push (push) Successful in 8s
Build image / build-and-push (push) Successful in 8s
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]>
This commit was merged in pull request #43.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// 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))
|
||||
}
|
||||
Reference in New Issue
Block a user