Issue accessing drafts from Astro SSR on Vercel with Sanity client token.

5 replies
Last updated: Mar 6, 2025
I’m trying to access drafts from Astro SSR on Vercel, I created a client with client with a token
const sanityAuthClient = sanityClient.withConfig(
  { 
    token: import.meta.env.SANITY_API_TOKEN, 
    useCdn: false
  }
);
with
Contributor permissions. Looks like that’s not enough. If I click on my preview link from studio in dev mode it actually loads fine.
Apr 3, 2024, 8:35 AM
Something sounds off here. In our docs we define that role as:> • Contributor: Read and write access to draft content within all datasets, with no access to project settings.
So I’d assume it would work.

Are you saying that same set up works locally, though? If that’s the case then I’d double check that your deployed version has access to your var.
Apr 3, 2024, 5:28 PM
Working now. Sorry I was assuming that when I ran
sanity deploy
the project was built before being deployed.
Apr 4, 2024, 9:18 AM
which actually shouldn’t have made a difference, anyway ya i think it was something about access to the env var.
Apr 4, 2024, 9:20 AM
Great!
Apr 4, 2024, 4:41 PM
user B
hi there, sorry this is an old thread but im actually running into the same issue currently. i have a contributor token and i can preview in dev mode, on vercel i have the same token (contributor permissions). my build and deployment was successful, however in my studio in production it is giving me an invalid secret. i was wondering if you had any tips or suggestions on how to debug this? I'm running Nextjs /react on the frontend deployed with vercel. the backend is actually in a separate repo which i deploy using the cli.
Mar 6, 2025, 1:21 AM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?