Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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
Hi
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 https://github.com/Marc-Kruiss/next_js_13_sanity_v3_setup
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?