N
Nuxtβ€’2mo ago
rxsto

The 'credentials' field on 'RequestInitializerDict' is not implemented.

Hey there, I am using NuxtHub to deploy to Cloudflare Pages and implemented authorization via session cookies. In order to forward the client cookies to the nuxt server when pre-rendering the page on sever-side I use the following code:
export default async function <T>(path: string, method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' = 'GET', body?: any): Promise<T> {
const { data, error } = await useFetch<T>(useRuntimeConfig().public.apiBaseUrl + path, {
headers: useRequestHeaders(['cookie']),
credentials: 'include',
body,
// @ts-ignore
method
})

if (error.value) {
throw error.value
}

return data.value as T
}
export default async function <T>(path: string, method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' = 'GET', body?: any): Promise<T> {
const { data, error } = await useFetch<T>(useRuntimeConfig().public.apiBaseUrl + path, {
headers: useRequestHeaders(['cookie']),
credentials: 'include',
body,
// @ts-ignore
method
})

if (error.value) {
throw error.value
}

return data.value as T
}
Specifically the part with headers: useRequestHeaders(['cookie']) and credentials: 'include', but it seems like the Request implementation on Cloudflare Pages/Workers does not include the credentials field. I am now wondering if there is a possibility to work around this issue? It feels like doing something like this should be possible, but I can't find any solution that would fix this problem. Any insight as to how I can proceed here would be greatly appreciated! Thanks (please ping me if you have an idea) 😊
1 Reply
rxsto
rxstoOPβ€’2mo ago
Alright, I fixed it by only providing the credentials: 'include' on client side, since it wasn't required on server side.
Want results from more Discord servers?
Add your server