Trouble with client.fetch() in Next.js 13 directory

3 replies
Last updated: Jun 5, 2023
I am trying to get Sanity running in the new app/page.js directory of Nextjs13. Why is client.fetch() not working here (where fetching jsonplaceholder does)? Please help.
Jun 3, 2023, 5:52 AM
user F
. Can you please elaborate on what’s not working? Are you getting an error, null, an empty array, etc.?
Jun 3, 2023, 2:31 PM
Thnx for your reply. Error: 'Failed to fetch data'. In the mean time found out the solution myself. See code from
Jun 3, 2023, 4:51 PM
this looks like you’re fetching data from Sanity on the client. and so you’ll need to ensure you’re making an authenticated request. if you move that logic into a Nextjs server function, things should work as is
Jun 5, 2023, 5:14 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?