I am trying to await a response to build my config. I am pulling in some data from a backend about some products that I want to use to populate this select statement:
{
name: 'layout',
type: 'select',
required: true,
options: [...(await getAllProducts())],
},
My getAllProducts function looks something like this:
export async function getAllProducts(): {
label: string; value: string
} {
const res = await fetch("my-backend-url.com/api/get-all-products");
const data = await res.json();
return data as { label: string; value: string };
}
To test to make sure this works, I'm using the below function as a proof-of-concept:
export const getAllProducts = async (): Promise<{ label: string; value: string }[]> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([
{ label: 'Product 1', value: 'product-1' },
{ label: 'Product 2', value: 'product-2' },
{ label: 'Product 3', value: 'product-3' },
])
}, 50)
})
}
But I'm getting the following error with the proof-of-concept code:
⨯ Internal error: TypeError: Cannot read properties of undefined (reading 'cookiePrefix')
at getRequestLanguage (./node_modules/.pnpm/@payloadcms+next@3.0.0-beta.11_@types+react@18.2.79_http-status@1.6.2_monaco-editor@0.47.0_ne_jaw7phd7jkcnpwawfivwmgj34a/node_modules/@payloadcms/next/dist/utilities/getRequestLanguage.js:8:46)
at RootLayout (./node_modules/.pnpm/@payloadcms+next@3.0.0-beta.11_@types+react@18.2.79_http-status@1.6.2_monaco-editor@0.47.0_ne_jaw7phd7jkcnpwawfivwmgj34a/node_modules/@payloadcms/next/dist/layouts/Root/index.js:44:110)
digest: "3908605137"
Any ideas if this works or how to resolve this?