content icon indicating copy to clipboard operation
content copied to clipboard

Support adding headers to query functions in v3

Open oripka opened this issue 1 year ago • 2 comments

I have sites where my content is only available for authenticated users. In v2 I needed to write code like this to inject the cookie when fetching content because to my knowledge queryContent() never really supported passing headers.

const params = `?_params={"first":true,"where":[{"_path":"${myRoute.value}"}],"sort":[{"_file":1,"$numeric":true}]}`
const headers = { ...useRequestHeaders(['cookie']) }
const page = await $fetch('/api/_content/query' + params, {
  headers,
  method: 'GET',
})

In the new version it seems again it is not possible to pass headers when querying. It would be a really nice feature because content might be available only to certain users and not public.

Support passing headers to

  • queryCollectionSearchSections
  • queryCollectionItemSurroundings
  • queryCollectionNavigation
  • queryCollection

I am also not sure how access to authenticated content is handled when this is used: WASM SQLite in Browser, can I just in the middleware allow access to /api/database.json if the user is authorized?

oripka avatar Nov 01 '24 08:11 oripka

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jan 16 '25 15:01 github-actions[bot]

@farnabaz is this something you would consider adding as feature, how is one supposed to secure access to private content?

oripka avatar Jan 17 '25 09:01 oripka