Skip to content

Client fetch not working #2710

@arturmeinzer

Description

@arturmeinzer

I created a new project, copied the code from another project where I use sanity. I just swap the project_id in the env file and the sanity write token. This always worked in the past, but now when I use the client, no matter what query I throw at it, it returns an empty result. If I use a writeClient with a token assigned, I get an result. This was never the case before and my dataset it public. I ended up using the writeClient all the time, but this is not a good solution.

Here is my client.ts:

import { createClient } from 'next-sanity'

import { apiVersion, dataset, projectId } from '../env'

export const client = createClient({
    projectId,
    dataset,
    apiVersion,
    useCdn: true, // Set to false if statically generating pages, using ISR or tag-based revalidation
})

And here my writeClient.ts:

import "server-only";

import { createClient } from 'next-sanity'

import { apiVersion, dataset, projectId, token } from '../env'

export const writeClient = createClient({
    projectId,
    dataset,
    apiVersion,
    useCdn: false,
    token,
});

if (!writeClient.config().token) {
    throw new Error("Write token not found!")
}

The real difference is the token. Does anybody have the same problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions