Joint session with Vercel: How to build intelligent storefronts (May 15th)

Access drafts from Astro SSR on Vercel with Sanity token permissions

5 repliesLast updated: Nov 30, 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.
AI Update

Looking at your setup, the issue is that the Contributor role doesn't have sufficient permissions to read drafts. According to the roles documentation, the Contributor role only has "create" mode access, which allows reading and writing to draft content but cannot read published documents or use the previewDrafts perspective.

Here's what's happening:

Contributor permissions:

Why it works in dev mode: In development, you're likely authenticated with your personal user account (which probably has Administrator or Editor role), so you have full access.

Solution options:

Quick fix: Go to your project's API settings, create a new token with Viewer role, and use that instead. Viewer tokens can read both drafts and published documents, which is exactly what you need for preview functionality on Vercel.

The Contributor role is designed for users who can create/edit content but shouldn't necessarily see everything - it's more restrictive than you need for a preview environment. For accessing drafts via the API (especially with perspectives like previewDrafts), you need at least Viewer-level permissions.

Show original thread
5 replies

Was this answer helpful?

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.

Related contributions