Dear Prismic team
I set up a new Next.js App Router project using your setup command npx @slicemachine/init@latest
and walking trough your step by step setup guide.
In previous versions, I never had issues deploying the site to Vercel and setting up Prismic Webhooks to trigger redeploys.
With this new project it seems like there are some caching issues with Vercel:
If I push a new commit to Github or if I edit content on Prismic, it triggers a new deploy correctly.
Unfortunately those deploys are missing the newest contents from Prismic and every then and now it appears the following error:
ForbiddenError: Access to this Ref requires an access token
at Client.fetch (/vercel/path0/.next/server/chunks/734.js:2367:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.get (/vercel/path0/.next/server/chunks/734.js:1450:16)
at async Client.dangerouslyGetAll (/vercel/path0/.next/server/chunks/734.js:1515:28)
at async Client.getAllByType (/vercel/path0/.next/server/chunks/734.js:1767:16)
at async Object.generateStaticParams (/vercel/path0/.next/server/app/portfolio/[portfolio]/[uid]/page.js:536:19)
at async buildParams (/vercel/path0/node_modules/next/dist/build/utils.js:917:36)
at async /vercel/path0/node_modules/next/dist/build/utils.js:934:33
at async /vercel/path0/node_modules/next/dist/build/utils.js:1067:117
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:103:20) {
url: 'https://my-repo.cdn.prismic.io/api/v2/documents/search?q=%5B%5Bat%28document.type%2C+%22project%22%29%5D%5D&pageSize=100&ref=ZLphbxEAACMAGdpk&routes=%5B%7B%22type%22%3A%22page%22%2C%22uid%22%3A%22home%22%2C%22path%22%3A%22%2F%22%7D%2C%7B%22type%22%3A%22page%22%2C%22path%22%3A%22%2F%3Auid%22%7D%2C%7B%22type%22%3A%22portfolio%22%2C%22path%22%3A%22%2Fportfolio%2F%3Auid%22%7D%2C%7B%22type%22%3A%22project%22%2C%22resolvers%22%3A%7B%22portfolio%22%3A%22portfolio%22%7D%2C%22path%22%3A%22%2Fportfolio%2F%3Aportfolio%2F%3Auid%22%7D%5D',
response: {
type: 'api_security_error',
message: 'Access to this Ref requires an access token',
oauth_initiate: 'https://my-repo.prismic.io/auth',
oauth_token: 'https://my-repo.prismic.io/auth/token'
}
}
In both cases I have to redeploy the site manually and force Vercel to not use the cache. If I do so, everything works fine.
Do you have any idea of how I can fix this?
In my prismicio.ts file I have the following recommended code which contains some lines about caching:
export const createClient = (config: prismicNext.CreateClientConfig = {}) => {
const client = prismic.createClient(repositoryName, {
routes,
fetchOptions:
process.env.NODE_ENV === 'production'
? { next: { tags: ['prismic'] }, cache: 'force-cache' }
: { next: { revalidate: 5 } },
...config,
});
prismicNext.enableAutoPreviews({
client,
previewData: config.previewData,
req: config.req,
});
return client;
};
Thanks for your support.